Providing object iterators beyond just Object.keys()

Gijs Kruitbosch gijskruitbosch at
Tue May 26 15:33:12 UTC 2015


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.

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)

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

More information about the es-discuss mailing list