数组的flat方法
Array.prototype.MyFlat = function () {
let arr = this
while (arr.some(item => Array.isArray(item))) {
arr = [].concat(...arr)
}
return arr
}
1
2
3
4
5
6
7
2
3
4
5
6
7
Array.prototype.MyFlat = function () {
let arr = this
while (arr.some(item => Array.isArray(item))) {
arr = [].concat(...arr)
}
return arr
}