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值