Skip to content

Instantly share code, notes, and snippets.

@jpjenkins
jpjenkins / merge nested arrays with .apply().js
Last active November 5, 2015 14:32
a nice use case for .apply() to merge nested arrays into a single array.
```
//If we have nested arrays of depth = 1:
var arr = [[1,2,3],[4,5],6];
//we can flatten it by using concat and apply
var flat_arr = [].concat.apply([],arr);
//and check the value
console.log(flat_arr);
//logs [1,2,3,4,5,6]
```