// 利用遞歸實現數組的扁平化let ary = [1, [2, [3, [4, 5]]], 6]; let result = []; let fn = function(ary){ for(let i = 0 ; i < ary.length; i++){ let item = ary[i] if ...
// 利用遞歸實現數組的扁平化
let ary = [1, [2, [3, [4, 5]]], 6];
let result = [];
let fn = function(ary){
for(let i = 0 ; i < ary.length; i++){
let item = ary[i]
if(Array.isArray(ary[i])){
fn(item);
} else {
result.push(item)
}
}
}
fn(ary);
console.log(result);