Table of contents
No headings in the article.
let output = [];
function flattenArray(arr) {
for (let i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
flattenArray(arr[i]);
} else {
output.push(arr[i]);
}
}
return output;
}
console.log(flattenArray([[[1, ['A']], 2, 3, 'B'], [4, 5, 'C'], 6]));
Output:
[1, 'A', 2, 3, 'B', 4, 5, 'C', 6]