SOURCE

const flatten = (arr) => arr.reduce((acc, item) => Array.isArray(item) ? acc.concat(flatten(item)) : acc.concat(item), [])

let arr = [1, [2, [3, 4]]];
console.log(flatten(arr))
console 命令行工具 X clear

                    
>
console