In CoffeeScript how do you append a value to an Array? In CoffeeScript how do you append a value to an Array? arrays arrays

In CoffeeScript how do you append a value to an Array?


Good old push still works.

x = []x.push 'a'


Far better is to use list comprehensions.

For instance rather than this:

things = []for x in list  things.push x.color

do this instead:

things = (x.color for x in list)


If you are chaining calls then you want the append to return the array rather than it's length.In this case you can use .concat([newElement])

Has to be [newElement] as concat is expecting an array like the one its concatenating to.Not efficient but looks cool in the right setting.