const arr = [1,2,[3,[4,5]],6] const result = arr.flat(Infinity) console.log(result) const result2 = JSON.stringify(arr).replace(/\[|\]/g, '').split(',') console.log(result2) const result3 = JSON.parse('['+JSON.stringify(arr).replace(/\[|\]/g, '')+']') console.log(result3) const result4 = [] const fn = arr => { for(let i=0; i<arr.length; i++) { if(Array.isArray(arr[i])) { fn(arr[i]) } else { result4.push(arr[i]) console.log(result4) } } } console.log(fn(arr)) // console.log(result4)