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

Solution 1:

Good old push still works.

x = []
x.push 'a'

Solution 2:

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)

Solution 3:

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.