js deep flatten array

Solutions on MaxInterview for js deep flatten array by the best coders in the world

showing results for - "js deep flatten array"
María
23 Jun 2018
1var deepFlatten = function (array){
2  return array.reduce(function(r, e) {
3    return Array.isArray(e) ? r.push(...deepFlatten(e)) : r.push(e), r
4  }, [])
5};
6
7console.log(deepFlatten([]))     
8console.log(deepFlatten([1, 2, 3]))
9console.log(deepFlatten([[1, 2, 3], ["a", "b", "c"], [1, 2, 3]]))
10console.log(deepFlatten([[[3], [4], [5]], [9], [9], [8], [[1, 2, 3]]]))
queries leading to this page
js deep flatten arrayjs deep flatten array