What is the JavaScript equivalent to a C# HashSet?

后端 未结 6 1444
天涯浪人
天涯浪人 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:17

    Use an object. To add a key to the set, do:

    object[key] = true;
    

    To test whether a key is in the set, do:

    if (object.hasOwnProperty(key)) { ... }
    

    To remove a key from the set, do:

    delete object[key]
    

提交回复
热议问题