We have a JavaScript array like:
How would we go about making this just:
We can use concat to merge arrays:
Using the apply method of concat will just take the second parameter as an array, so the last line is identical to this:
Here's a short function that uses some of the newer JavaScript array methods to flatten an n-dimensional array.
Usage:
Here's a simple and performant functional solution:
It can be best done by javascript reduce function.
Or, with ES2015:
We can use Underscore :