[英]What is the most efficient way to display and rename only the keys from a nested JSON?
我不太確定我明白你真正想要什么,但如果結構相同,你可以做類似的事情
let result: string[] = [];
const nameMap = {
act: 'Actual',
plan: 'Planning',
prognosis: 'Prog'
};
Object.keys(actAndPlanBalance).forEach(x => {
if (actAndPlanBalance[x]['act']) result.push(nameMap.act);
else if(actAndPlanBalance[x]['plan']) result.push(nameMap.plan);
else if(actAndPlanBalance[x]['prognosis']) result.push(nameMap.prognosis);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.