标签:class mamicode image inf div 小明 修改 val obj
var array = [
{
id:1,
name:"小明"
},
{
id:2,
name:"小红"
}
];
/**/
//旧key到新key的映射
var keyMap = {
"id" : "value",
"name" : "label"
};
for(var i = 0;i < array.length;i++){
var obj = array[i];
for(var key in obj){
var newKey = keyMap[key];
if(newKey){
obj[newKey] = obj[key];
delete obj[key];
}
}
}
console.log(array);
原地址:https://segmentfault.com/q/1010000015794387
修改key值
标签:class mamicode image inf div 小明 修改 val obj
原文地址:https://www.cnblogs.com/IwishIcould/p/11780195.html