0
這是我的嵌套對象,我需要閱讀並轉換。如何讀取並將嵌套對象轉換爲具有所需數據的另一個對象?
{
"_id": "config",
"_rev": "11-57a",
"config": {
"A": {
"a1": {
"required": true,
"editable": true
},
"a2": {
"required": true,
"editable": true
},
"a3": {
"required": false,
"editable": false
},
"a4": {
"required": false,
"editable": true
},
"a5": {
"required": true,
"editable": true
},
"a6": {
"required": false,
"editable": true
}
},
"B": {
"b1": "b22",
"b2": "b23"
},
"C": {
"c1": "c22",
"c2": "c33"
}
}
}
我要讀上面的數據並轉換成以下格式
{
"_id":"config",
"config":{
"A":{
"a1":{"required":true},
"a2":{"required":true},
"a3":{"required":false},
"a4":{"required":false},
"a5":{"required":true},
"a6":{"required":false}
}
}
}
我如何轉換這樣在JavaScript?
遍歷源對象,例如與Object.entries,Object.keys或類似的,並將您選擇的屬性寫入新對象。 – Christoph
你只想保留任何具有所需屬性的東西? –
@AdooSanchez是的,我想這樣做 – radiance88