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 }); });