Generate a Hash from string in Javascript

前端 未结 22 982
不知归路
不知归路 2020-11-22 03:34

I need to convert strings to some form of hash. Is this possible in JavaScript?

I\'m not utilizing a server-side language so I can\'t do it that way.

22条回答
  •  别跟我提以往
    2020-11-22 04:14

    My quick (very long) one liner based on FNV's Multiply+Xor method:

    my_string.split('').map(v=>v.charCodeAt(0)).reduce((a,v)=>a+((a<<7)+(a<<3))^v).toString(16);
    

提交回复
热议问题