Providing object iterators beyond just Object.keys()

Domenic Denicola d at domenic.me
Tue May 26 15:34:58 UTC 2015


http://lmgtfy.com/?q=site%3Aesdiscuss.org+object.values

From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Gijs Kruitbosch
Sent: Tuesday, May 26, 2015 10:33
To: es-discuss at mozilla.org
Subject: Providing object iterators beyond just Object.keys()

Hello,
When writing JS loops over objects, given the environment I'm in, I find myself using the gecko/spidermonkey-only "Iterator()" construct a lot for loops or array comprehensions:
for (let [key, val] of Iterator(plainJSObject)) {
   // do stuff with both key and val
}
It seems the plan is to remove "Iterator()" (cf. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator ).
Are there plans to add things like Object.values() (to produce Object.keys(obj).map(k => obj[k]) ) or Object.iterator (Object.keys(obj).map(k => [k, obj[k]])) so as to enable such usecases to be written easily in ES7 or later? Obviously I can create my own iterator, but it starts to get tedious if I need to do this in every file where I need to iterate over an object's own (enumerable) properties...
(using Maps here is difficult because writing hardcoded nested structures of Maps is not nearly as neat as doing the same with Objects)
Gijs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150526/58e56932/attachment.html>


More information about the es-discuss mailing list