javescript 字符串生成 hash 值
生活随笔
收集整理的這篇文章主要介紹了
javescript 字符串生成 hash 值
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
用來對比字符串是否一致,一般是判斷已有文本是否被再次編輯。
function hashVal(string){var hash = 0, i, chr;if (string.length === 0) return hash;for (i = 0; i < string.length; i++) {chr = string.charCodeAt(i);hash = ((hash << 5) - hash) + chr;hash |= 0; // Convert to 32bit integer}return hash; } let string = '你好有緣人'; console.log(hashVal(string)); // -2000030674總結(jié)
以上是生活随笔為你收集整理的javescript 字符串生成 hash 值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flutter 在阿里淘系的体系化建设和
- 下一篇: c++计算hash值