Which built-in object stores a collection of unique values?

The story behind the answer

The built-in object that stores a collection of unique values is Set.

A Set can hold values of any JavaScript type, including numbers, strings, booleans, objects, and symbols. Each value can appear only once, so adding a duplicate has no effect. Sets also preserve insertion order when you iterate through them, which makes them useful for removing duplicates while retaining the original sequence.

Set is often confused with Array, but arrays allow duplicates and are primarily indexed by position. Map stores key-value pairs, not standalone unique values. WeakSet also stores unique entries, but it is limited to objects and non-registered symbols and is designed for weak garbage-collection behavior. For a general-purpose collection of unique JavaScript values, Set is the canonical answer.

A common pattern is [...new Set(items)], which converts an array into a duplicate-free array. Set membership is tested with has(), and entries can be added or removed with add() and delete().

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: