办法一:递归
var arr3 = [1,[2,3],[2,[1,3]],[[2,4],[2,8]]]
function flaten(arr){let result = [];
arr.forEach((item)=>{if(Array.isArray(item)){result = result.concat(flaten(item))
}else{result.push(item)
}
})
return result
}
console.log(flaten(arr3))
办法二:reduce+ 递归
function flatenReduce (arr){return arr.reduce((res,item)=>{return res.concat(Array.isArray(item)?flatenReduce(item):item)
},[])
}
console.log(flatenReduce(arr3))