安河桥北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日

悬赏问题

  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了