js循环修改数组属性key值

var keyMap = {
            deviceUid: "id",
            deviceType: "typeName",
            deviceCode: "code",
            deviceName: "name",
            deviceStatus: "status"
          };
          for (var i = 0; i < data.confList.length; i++) {
            var obj = data.confList[i];
            for (var key in obj) {
              var newKey = keyMap[key];
              if (newKey) {
                obj[newKey] = obj[key];
                delete obj[key];
              }
            }
          }
          console.log("array", data.confList);

或者重新建一个[]

然后重新push

let itemArr = [];
      this.deviceTableData_ys_true.map(item => {
        itemArr.push({
          deviceUid: item.id,
          deviceId: item.deviceId
        });
      });

  再或者 

 //修改属性名对应
            let arryNew = [];
            datas.map((item, index) => {
              arryNew.push(Object.assign({}, item, { name: item.moduleName }));
              return arryNew;
            });
            this.List = arryNew;

 

posted @ 2019-08-09 16:07  abcByme  阅读(11696)  评论(0编辑  收藏  举报