安河桥北278 2022-07-20 15:22 采纳率: 20%
浏览 40
已结题

怎样将两个数组对象合并为一个数组?

怎样将两个数组对象合并为一个数组?
vue代码如下

 //获取分类属性列表
    async getCategoryAttributeList() {
      const categoryMap = {
        categoryCode: this.categoryCode,
      };
      const { data } = await getCategoryDetails(categoryMap);
      const results = data;
      this.attvaluearr = results;
      const map = new Map();
      const qc = results.filter(
        (key) => !map.has(key.AttName) && map.set(key.AttName, 1)
      ); // 这里对name属性进行去重
      let new_arr = qc.map((obj) => {
        return obj.AttName;
      });
      let new_arr1 = qc.map((obj) => {
        return obj.AttCode;
      });
      var array = [];
      for (var item of new_arr) {
        console.log(item);
        var obj = new Object();
        obj.AttName = item;
        array.push(obj);
      }
      for (var item of new_arr1) {
        var obj1 = new Object();
        obj1.AttCode = item;
        array.push(obj1);
      }
      this.attnamearr = array;
      console.log(this.attnamearr);
    },

目前attnamearr控制台打印为这样格式数据

Proxy {0: {…}, 1: {…}, 2: {…}, 3: {…}, 4: {…}, 5: {…}, 6: {…}, 7: {…}, 8: {…}, 9: {…}, 10: {…}, 11: {…}, 12: {…}, 13: {…}, 14: {…}, 15: {…}, 16: {…}, 17: {…}, 18: {…}, 19: {…}, 20: {…}, 21: {…}}
[[Handler]]: Object
[[Target]]: Array(22)
0: {AttName: 'IP等级'}
1: {AttName: '产地'}
2: {AttName: '停产'}
3: {AttName: '分线器类型'}
4: {AttName: '分线盒类型'}
5: {AttName: '协议类型'}
6: {AttName: '安装孔'}
7: {AttName: '安装方式'}
8: {AttName: '导体横截面'}
9: {AttName: '屏蔽'}
10: {AttName: '指示灯数量'}
11: {AttCode: '1000'}
12: {AttCode: '1001'}
13: {AttCode: '1002'}
14: {AttCode: '1003'}
15: {AttCode: '1004'}
16: {AttCode: '1005'}
17: {AttCode: '1006'}
18: {AttCode: '1007'}
19: {AttCode: '1008'}
20: {AttCode: '1009'}
21: {AttCode: '1010'}


希望将attnamearr变成如下格式数据

Proxy {0: {…}, 1: {…}, 2: {…}, 3: {…}, 4: {…}, 5: {…}, 6: {…}, 7: {…}, 8: {…}, 9: {…}, 10: {…}}
[[Handler]]: Object
[[Target]]: Array(11)
0: {AttName: 'IP等级' , AttCode: '1000'}
1: {AttName: '产地' , AttCode: '1001'}
2: {AttName: '停产' , AttCode: '10002'}
3: {AttName: '分线器类型' , AttCode: '1003'}
4: {AttName: '分线盒类型' , AttCode: '1004'}
5: {AttName: '协议类型' , AttCode: '1005'}
6: {AttName: '安装孔' , AttCode: '1006'}
7: {AttName: '安装方式' , AttCode: '1007'}
8: {AttName: '导体横截面' , AttCode: '1008'}
9: {AttName: '屏蔽' , AttCode: '1009'}
10: {AttName: '指示灯数量' , AttCode: '1010'}

  • 写回答

1条回答 默认 最新

  • Z_ One Dream 2022-07-20 15:29
    关注
        var array = [];
        for (let i = 0; i < new_arr.length; i++) {
            const value1 = new_arr[i]
            const value2 = new_arr1[i]
            var obj = new Object();
            obj.AttName = value1;
            obj.AttCode = value2;
            array.push(obj);
          }
          this.attnamearr = array;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 7月28日
  • 已采纳回答 7月20日
  • 创建了问题 7月20日

悬赏问题

  • ¥20 c语言写的8051单片机存储器mt29的模块程序
  • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
  • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。
  • ¥50 rk3588板端推理
  • ¥250 opencv怎么去掉 数字0中间的斜杠。
  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥250 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大