ES6 iteration over object values

C. Scott Ananian ecmascript at
Sat Mar 15 22:22:18 PDT 2014

On Sat, Mar 15, 2014 at 6:19 PM, David Bruant <bruant.d at> wrote:
> Le 15/03/2014 22:51, C. Scott Ananian a écrit :
> It would be nicer to add an Object.entries() method that would return that
> iterator.
> Object.prototype.entries or Object.entries(obj)?

`Object.entries(obj)` and `Object.values(obj)` (as suggested by Jason).

The linked resolution for `Dict`
was less than clear, but generic `Dict.keys(obj)`,
`Dict.entries(obj)`, and `Dict.values(obj)` which can take arbitrary
objects (not just objects with no prototype) would be an okay
fallback.  It leaves `Object.keys` an orphan, alas.
`` would be too long to be useful (but
I don't think that was being proposed).

for (let [key, value] of Dict.entries(myObj)) {
   // do something with key|value

That's not too bad.  Shorter than `Object.entries`, even.  (But I
personally don't see the point of `new Dict()` instead of
`Object.create(null)`, and prefer the `Object.*` names.)

More information about the es-discuss mailing list