Set.prototype.entries: indices as keys?

Axel Rauschmayer axel at rauschma.de
Sun Jan 18 04:28:01 PST 2015


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”]]

Rationale: First, having an indices as keys makes the entries more useful. Second, destructuring already treats entries as if they had indices:

```js
let [x,y] = set; // x='a'; y='b’;
```

-- 
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150118/1fb69fdf/attachment.html>


More information about the es-discuss mailing list