简体   繁体   中英

Make the hash value unique in javascript?

For example I am having the hash

 var sample={};
 sample["test"] = [];
 sample["test"].push({name: "test"});
 sample["test"].push({name: "test"});

The sample hash should only contain unique values.

Yes i got the solution for that

var sample = [{ id : 1, name : 'Name' }, { id : 1, name : 'Name' }];
var obj = { id : 1, name : 'Name' };
var sample = [obj, obj];
uniq(sample)

Hej man it isn't possible to got another hash value from 2 same value's. For simplify a hash operation is likely like plus so you got 1 + 2 = 3. It is not that easy but I hope you got he point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM