数组

1.合并数组,其中一项相加(id相同)

let res = []

 let arr = JSON.parse(JSON.stringify(this.child))

   res =  Object.values(arr.reduce((t,c)=>{

       (!t[c.id] && (t[c.id]= c)) || (t[c.id] && (t[c.id].num += c.num));

            return t;

    }, {}));

2.合并数组,找到相同项去重

 const res = new Map();

  let c = this.child.filter((a)=> !res.has(a.id) && res.set(a.id,1))

3.记录数组的个数,以数组一项作为箭值.组成对象

 this.childSel = new Object();

       for(let i in this.child){

        var id = this.child[i].id

          if(this.childSel[id]===undefined){

            this.childSel[id] = 1

          }else{

            this.childSel[id] +=1

          }

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容