1.toString+split
//1.toString+split
var arr = [1, [2, [3, 4]],
[55, [1, [5], 8]]
];
console.log(arr.toString().split(','));
2.递归+isArray
//2.递归+isArray
var arr1 = [1, [2, [3, 4]],
[55, [1, [5], 8]]
];
function fn(arr1) {
let newArr = []
arr1.map((item) => {
if (Array.isArray(item)) {
newArr = newArr.concat(fn(item))
} else {
newArr.push(item)
}
console.log(newArr);
})
return newArr
}
console.log(fn(arr1));