【发布时间】:2020-11-09 14:21:58
【问题描述】:
目前对于我们的导航结构,我们有以下数组:
{
childNodes: [
{title: "Mijn afdeling", type: "Department", relativeUri: "/mijnafdeling"},
{title: "contact", type: "Department", relativeUri: "/contact"}
]
RelativeUri: '/',
title: 'test'
},
{
childNodes: null
RelativeUri: '/',
title: 'test'
}
]
现在我想将所有 'childNodes' 键更改为 'child' 并将所有 relativeUri 键更改为 href。
我想要的结果应该是
{
child: [
{title: "Mijn afdeling", type: "Department", href: "/mijnafdeling"},
{title: "contact", type: "Department", href: "/contact"}
]
href: '/',
title: 'test'
},
{
child: null
href: '/',
title: 'test'
}
]
我知道我可以执行类似this.navigationArray = this.navigationArray.map(({ childNodes, relativeUri }) => ({ childNodes: child, href: relativeUri })) 的操作,但是我也不知道如何获取 childNodes 对象下数组中的所有键。所以它基本上需要“查找”或遍历数组中的所有对象,并找到特定的键。 'childNodes' 对象也可以为 null。
对于不同的页面,我有不同数量的导航项,所以我宁愿不针对特定的索引,因为这会扰乱导航。
非常感谢!
【问题讨论】:
标签: arrays loops dictionary key