coffeescript Arrays Concatenation


Example

You want to combine arrays into one.

For example, you have

fruits = ['Broccoli', 'Carrots']
spices = ['Thyme', 'Cinnamon']

and you want to combine them into

ingredients = ['Broccoli', 'Carrots', 'Thyme', 'Cinnamon']

Method 1 - using .concat

ingredients = fruits.concat spices

Method 2 - using splats

ingredients = [fruits..., spices...] 

Method 3 - using .concat with indeterminate number of arrays

If the number of arrays can vary, e.g. you have array of arrays:

arrayOfArrays = [[1], [2,3], [4]]
[].concat.apply([], arrayOfArrays) # [1, 2, 3, 4]