Skip to content

Instantly share code, notes, and snippets.

const flatten = (array) => {
let flattened = [];
for (const item of array) {
flattened = flattened.concat(Array.isArray(item) ? flatten(item) : item);
}
return flattened;
};
console.log(flatten([[1,2,[3]],4])); // [1, 2, 3, 4]