我開始學習lodash,無法理解如何將鍵移動到同一對象的另一個鍵。從API我得到下一個數據(用戶列表):如何通過lodash將某些鍵移動到另一個對象的鍵上?
[
{
"id": 1,
"username": "test1",
"phone": null,
"email": "[email protected]",
"role": "admin",
"language": "en",
"created_at": "2016-12-16 14:25:23",
"updated_at": "2016-12-16 14:25:23"
}, ... ]
,我希望得到
[
{
"hidden": {
"id": 1,
"username": "test1",
"language": "en",
"created_at": "2016-12-16 14:25:23",
"updated_at": "2016-12-16 14:25:23"
},
"phone": null,
"email": "[email protected]",
"role": "admin"
},
{
"hidden": {
"id": 2,
"username": "test2",
"language": "en",
"created_at": "2017-09-22 10:45:00",
"updated_at": "2017-09-22 10:45:00"
},
"phone": null,
"email": "[email protected]",
"role": "moderator"
}
]
welcome :)的確,ES6傾向於創建乾淨的代碼。但是請注意,對象休息/傳播不是ES6,而是一個提議,並且您需要使用轉換插件的babel。 –