CoffeeScript – enumerate array / get index during for loop

Turns out there’s always a second parameter passed to a for loop which is the index.

How shockingly convenient.

for value in list
console.log value

for value, index in list
console.log value, index

4 Comments

  1. Ardee Aram says:

    Thanks, great help!

  2. 4ken says:

    Is it working with nested objects?

  3. Kyle says:

    This is the answer I’ve been searching for on Google for hours! Thank you!

  4. nocdib says:

    Thanks. This was a help to me.

Leave a Comment