Set.prototype.entries: indices as keys?

Mark Volkmann r.mark.volkmann at gmail.com
Sun Jan 18 05:10:49 PST 2015


+1

---
R. Mark Volkmann
Object Computing, Inc.

> On Jan 18, 2015, at 6:28 AM, Axel Rauschmayer <axel at rauschma.de> 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”]]
> 
> 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
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150118/5160b447/attachment.html>


More information about the es-discuss mailing list