拍平一个数组 [1,2,[3,4,5,[6,7,8],9],10,[11,12]] 用reduce不能用flat
//forEach function fn(arr) { let arr1 = [] arr.forEach((val) => { if(val instanceof Array) { arr1 = arr1.concat(fn(val)) }else { arr1.push(val) } }); return arr1 } //reduce function fn(arr) { return arr.reduce((prev,cur) =>{ return prev.concat(Array.isArray(cur) ? fn(cur) : cur) }) }