Mimicking sets in JavaScript?

前端 未结 7 2130
栀梦
栀梦 2020-11-22 13:01

I\'m working in JavaScript. I\'d like to store a list of unique, unordered string values, with the following properties:

  1. a fast way to ask \'is A in t
7条回答
  •  孤城傲影
    2020-11-22 13:34

    Yes, that's a sensible way--that's all an object is (well, for this use-case)--a bunch of keys/values with direct access.

    You'd need to check to see if it's already there before adding it, or if you just need to indicate presence, "adding" it again doesn't actually change anything, it just sets it on the object again.

提交回复
热议问题