文章阅读

沉浸阅读完整内容

写文章

数组如何递归降维

正在统计阅读人数 正在统计字数
登录收藏0
字号 100%

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());

推荐阅读

4 篇精选
文章 / 90vue 配置自动加载sass 文章 / 89vue 组件通信传递参数(任意组件传递) 文章 / 92vue 全局过滤器filter 文章 / 91vue ref获取dom节点

发表评论

评论 0

还没有评论,欢迎留下第一条讨论。

分享精彩,传递价值

生成专属海报,分享你的文章,让更多人发现好内容

浏览器不支持 Canvas,无法生成海报。

每日签到

每天来这里,记录一点持续积累。

当前积分--积分
本月签到--
本月获得--积分
正在读取