const arrayStr = [{code: '1', name: 'jack'}];
let keyMap = {
"code": "value",
"name": "label"
}
for (let i = 0; i < arrayStr.length; i++) {
const obj = arrayStr[i];
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const newKey = keyMap[key];
if (newKey) {
obj[newKey] = obj[key];
delete obj[key];
}
}
}
}
网友评论