欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js循环修改数组属性key值

程序员文章站 2023-11-10 20:45:04
或者重新建一个[] 然后重新push ......
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
        });
      });