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

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

怎样将两个数组对象合并为一个数组?
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 请问这种量表怎么用spss量化分析(作为中介模型的因变量
  • ¥55 AD844 howland电流源如何驱动大额负载
  • ¥15 C++ /QT 内存权限的判断函数列举
  • ¥15 深度学习GFnet理解问题
  • ¥15 单细胞小提琴堆叠图代码
  • ¥50 升级strust2版本到2.3.15.1后使用ognl3.0.6.jar windows环境中没有问题,但部署到linux环境报错
  • ¥15 vue页面,node封装接口
  • ¥15 求TMS320F280039C工程模板!
  • ¥15 delphi+fastreport实现分组补空打印问题
  • ¥15 使用python把两台mysql数据库服务器数据导出和导入