Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to concat nested array in javascript

const arr = [1, 2, [3, 4]];

// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]

// or with decomposition syntax
const flattened = arr => [].concat(...arr);
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #concat #nested #array #javascript
ADD COMMENT
Topic
Name
1+7 =