let arr = [1,2,3,[3,4,5,[8,9,76,[3,3,[1]]],3,3,4],3] while(arr.some((item)=>Array.isArray(item))){ arr = [].concat(...arr) } while(arr.some((item)=>Array.isArray(item))){ arr = [].concat(...arr); } console.log(arr)