JSworkinges2015

The Set Data Structure

Collections, refined.

A Set holds a collection of values like an array — except every member is unique. The dedup happens for free, and the lookups are O(1).

Basic dedup

JSintro
Press Run to execute

The first line collapses the repeated 2s and 3s to [1, 2, 3, 4]; the second keeps only the distinct letters of "mississippi" in first-seen order — m, i, s, p. Insertion order is preserved, which the old Object.keys dedup trick can't promise.