JSFiddle - React, Tailwind, and code Playground
by ecropolis
JavaScript
var test = [[1,2,[3]],4];
var test2 = [1,2,3,4];
function flatten(arr){
var result = [];
var process = function(){
arr.forEach(ele){
if(typeof ele === 'object'){
process(ele);
} else {
result.push(ele);
}
});
};
process(arr);
return result;
}