for statement with index and value

Jonathan Bond-Caron jbondc at
Tue Jul 14 11:45:01 UTC 2015

On Mon Jul 13 10:22 PM, Kevin Smith wrote:

> Destructuring is here to help:
>     for (let [index, value] of [1, 2, 3].entries()) 
>         console.log(index + ": " + value)
> The "entries" method returns an iterator of [index, value] pairs.

Can't there be a 'key iterator' syntax?

for (let value, index of [1, 2, 3]) 
         console.log(index + ": " + value)

let value =;
let index=;

- An array has an implicit 'key iterator' cause there's a key for each value.
- Everything else has a 'keyIteratorFrom0ToInifinity'

So you have a 'value iterator' and a 'key iterator' for each thing on the RHS.
Doesn't seem like much of an issue, engines just need a keyIteratorFrom0ToInifinity for non-array things cases.

More information about the es-discuss mailing list