for statement with index and value
jbondc at gdesolutions.com
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 = itOfValues.next().value;
let index= itOfKeys.next().value;
- 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