Open DamomHd opened 3 years ago
arr = arr.flat(Infinity)
arr = str.replace(/(\[|\])/g,'').split(',')
str = str.replace(/(\[|/])/g,'')
str = '[' + str + ']'
arr = JSON.parse(str)
let result = []
function myFlat(arr){
for(let i = 0;i<arr.length;i++){
let item = arr[i]
if(Array.isArray(item)) {
myFlat(item)
}
else{
result.push(item)
}
}
return result
}
function myFlat(arr){
return arr.reduce((pre,cur)=>{
return pre.concat(Array.isArray(cur) ? myFlat(cur) : cur)
}, [])
}
function myFlat(arr){
while (arr.some(Array.isArray)){
arr = [].concat(...arr)
}
return arr
}
多维数组=》一维数组