js合并两个数组对象

来自:https://www.cnblogs.com/keleyz/p/10118648.html 侵删

let d = [];
            let d2 = [];
            result3[1].forEach((item, index) => {
              d.push({
                name: item,
              });
            });
            result3[2].forEach((item, index) => {
              d2.push({
                num: item,
              });
            });
            this.datacloud = this.merge(d,d2,'num')
merge(a, b, attrName) {
      let attr = attrName;
      b.map((value, index) => {
        //数组b 长度大于a的长度时,需要判断
        if (a[index] !== undefined) {
          a[index][attr] = value[attr];
        } else {
          return;
        }
      });
      return a;
    },

 

posted @ 2024-06-27 17:20  abcByme  阅读(9)  评论(0编辑  收藏  举报