How can I get the index of a CoffeeScript .each loop? I've searched everywhere and can't seem to find a solid answer. I know how I can do this with vanilla jQuery, but I can't figure out how to add the index argument to function() in CoffeeScript.
here is my code currently:
video_list_element = $('#video-list li')
video_list_element.each ->
video_list_element.delay(100).animate({
"top": "0"
}, 2000)
I'm trying to multiply the value inside of .delay() by the index of the .each loop
Thank you so much for your help, I really appreciate it!!!
Regards, Tim
Documentation for the jQuery .each() function is found here: http://api.jquery.com/each/
video_list_element = $('#video-list li')
video_list_element.each (index, element) ->
element.delay(100 * index).animate "top": "0", 2000
In general (sans-jQuery), the way to get the index in a coffeescript for loop is:
array = ["item1", "item2", "item3"]
for value, index in array
console.log index, value
Gives:
0 item1
1 item2
2 item3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With