Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Flatten a multidimension array

// ES5 version
let flattened = [[1, 2], [3, 4], [5, 6]].reduce(function (acc, curVal) {
  return acc.concat(curVal)
}, []);

// ES6 version
let flattened = [[1, 2], [3, 4], [5, 6]].reduce((acc, curVal) => acc.concat(curVal), []);

console.log(flattened); // [1,2,3,4,5,6]
Source by codeburst.io #
 
PREVIOUS NEXT
Tagged: #Flatten #multidimension #array
ADD COMMENT
Topic
Name
6+5 =