JSFiddle - React, Tailwind, and code Playground
by slace
JavaScript
function flatten(a){
var result = [],first;
while (a.length) {
first = a.shift();
if (toString.call(first)=="[object Array]") {
a = first.concat(a);
} else {
result.push(first);
}
}
return result;
}
var data = [
[ [1, [4,5]], [2, { foo: ['bar','baz'] }], [3, [6,7,[8],9]] ]
];
console.log(flatten(data));