数组递归降维代码
时间:2023-9-18 09:06 作者:六思逸 分类: JavaScript
Array.prototype.myReduce = function () {
let newArr = [];
for (let item of this) {
if (Array.isArray(item)) {
newArr = newArr.concat(item.myReduce());
} else {
newArr.push(item);
}
}
return newArr;
};
// 多维数组
let arr = [1, 2, [3, 4, [5, 6, [7, 8, [9, 10]]]]];
console.log(arr.myReduce());
标签: 数组递归降维代码
扫描二维码,在手机上阅读
推荐阅读:
评论:
小小的人 2023-10-10 17:26
你干嘛