for statement with index and value
Matthew Robb
matthewwrobb at gmail.com
Tue Jul 14 13:22:57 UTC 2015
Why not use the new meta syntax?
for (let value of values) {
console.log(for.index);
}
- Matthew Robb
On Tue, Jul 14, 2015 at 7:45 AM, Jonathan Bond-Caron <
jbondc at gdesolutions.com> wrote:
> 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.
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150714/ab6ad392/attachment-0001.html>
More information about the es-discuss
mailing list