0

Trying to do something simple but hitting a brick wall. I'm trying to get the index value of an item in an array, I'm using Coffeescript not plain Javascript.

Code:

for i in ["The Royal Family", "Residences", "History & Tradition", "News", "Events", "Jobs"]
    createSubMenuLayer(i, i.value)

I've tried i.index, i.value, plain old i (which gives me the string). I want to get the index value to position items based upon the position in the array.

Cheers.

Andrew
  • 141
  • 2
  • 11

1 Answers1

0

The for x in ... form of the for loop iterates over the values of an array, not the indexes. But the documentation says:

# Fine five course dining.
courses = ['greens', 'caviar', 'truffles', 'roast', 'cake']
menu i + 1, dish for dish, i in courses
# -------------------^^^^^^^

So you're looking for this:

for e, i in [...]
    createSubMenuLayer(i, e)
mu is too short
  • 426,620
  • 70
  • 833
  • 800