Is there any kind of hash code function in JavaScript?

后端 未结 20 1175
慢半拍i
慢半拍i 2020-12-04 09:59

Basically, I\'m trying to create an object of unique objects, a set. I had the brilliant idea of just using a JavaScript object with objects for the property names. Such as,

20条回答
  •  北海茫月
    2020-12-04 10:43

    I put together a small JavaScript module a while ago to produce hashcodes for strings, objects, arrays, etc. (I just committed it to GitHub :) )

    Usage:

    Hashcode.value("stackoverflow")
    // -2559914341
    Hashcode.value({ 'site' : "stackoverflow" })
    // -3579752159
    

提交回复
热议问题