What is the JavaScript equivalent to a C# HashSet?

后端 未结 6 1435
天涯浪人
天涯浪人 2020-12-13 23:39

I have a list of a few thousand integer keys. The only thing I need to do with this list is say whether or not a given value is in the list.

For C# I would use a

6条回答
  •  北海茫月
    2020-12-14 00:03

    Actually JavaScript provides a Set object, fairly simple to use:

    var set = new Set();
    set.add(1);
    set.add(2);
    
    set.has(1)    // true
    

    Unfortunately, it is not compatible with IE9.

提交回复
热议问题