let manyArr = [[5, 7, 4], 3, [89, [8, 9]]]; // 需要处理的目标数组
function flat(arr) {
let newArr = []
for (let _i = 0; _i < arr.length; _i++) {
// 这里判断当前下标的值 是否还是数组类型
if (Object.prototype.toString.call(arr[_i]).slice(8, -1) == 'Array') {
newArr = [...newArr, ...flat(arr[_i])]
} else {
newArr.push(arr[_i]);
}
}
return newArr
}
manyArr = flat(manyArr);