OneCompiler

convert nested arrays into single array

146

function flattenArray(arr) {
return arr.flatMap(item => Array.isArray(item) ? flattenArray(item) : item);
}

const arr2 = [0, 1, [2, [3, [4, 5]]]];
const flatArray = flattenArray(arr2);

console.log(flatArray);