Set.prototype.entries: indices as keys?

Rick Waldron waldron.rick at
Sun Jan 18 12:59:51 PST 2015

On Sun Jan 18 2015 at 7:28:15 AM Axel Rauschmayer <axel at> wrote:

> Currently the keys of the entries returned by `Set.prototype.entries()`
> are the same as the values:
> ```js
> let set = new Set(['a', 'b']);
> let pairs = [...set.entries()];
> console.log(JSON.stringify(pairs)); // [["a","a"],["b","b”]]
> ```
> Given that sets are ordered, I’d use the “position” of an entry as the
> key: [[0,"a"],[1,"b”]]

Sets are not a linear data structure, so the order of entries in a Set is
irrelevant, unlike an Array whose elements must have an explicit position.
Set entries in JS have an iteration order purely to match programmer
intuition (and ensure that all implementations adhere), however there is no
structural importance of the order.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list