Answers for "how to concat nested array in javascript"

0

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);
Posted by: Guest on March-01-2022

Code answers related to "how to concat nested array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language