const data = [1, [2, [3, [4, 5]]]];
let newArr = []function isOnedimensionArray(arr){
arr.forEach((item)=>{
if(Array.isArray(item)){
isOnedimensionArray(item)
}else{
newArr.push(item)
}
})
}isOnedimensionArray(data)
console.log(newArr,'newArray')
输出:
(5) [1, 2, 3, 4, 5]0: 11: 22: 33: 44: 5length: 5[[Prototype]]: Array(0) 'newArray'