Getting the first and last element of an array in CoffeeScript

Viewed 30797

If say I have an array and I would to iterate through the array, but do something different to the first and last element. How should I do that?

Taking the below code as example, how do I alert element a and e?

array = [a,b,c,d,e]
for element in array
  console.log(element)

Thanks.

6 Answers
Related