const flattenArray = arr => { const flattened = [].concat(...arr); return flattened.some(v => Array.isArray(v))?flattenArray(flattened):flattened; } const arr = [1,[2,3,[3.1,3.2]],4]; console.log(flattenArray(arr)); //[1, 2, 3, 3.1, 3.2, 4]
const flattenArray = arr => { const flattened = [].concat(...arr); return flattened.some(v => Array.isArray(v))?flattenArray(flattened):flattened; } const arr = [1,[2,3,[3.1,3.2]],4]; console.log(flattenArray(arr)); //[1, 2, 3, 3.1, 3.2, 4]