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

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

怎样将两个数组对象合并为一个数组?
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条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

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

      悬赏问题

      • ¥15 边界图中的x、y轴解释
      • ¥30 如何用matlab求解复杂方程
      • ¥15 VUE TS中怎么调用第三方js
      • ¥15 Activiti如何将值传入textValue
      • ¥20 在linux里安装lummps时 在make mpi里找不到rpc
      • ¥25 python先到先得调度和轮询调度
      • ¥15 SDK Manager闪退
      • ¥15 intel i219v mac地址修改问题
      • ¥15 leetcode上面的题,求解
      • ¥15 PHP,访问接口500错误