Search code examples
javascriptcollectionssetduplicatesno-duplicates

Does Javascript supports Sets?


Does Javascript supports Sets(list with unique objects only) ?

I have found this link, but from what I remember foreach in JS in not supported by every browser.


Solution

  • Are your keys strings?

    Every JavaScript object is a map, which means that it can represent a set.

    As illustrated in the page you mentioned, each object will accept only one copy of each key (attribute name). The value for the key/attribute doesn't matter.