【发布时间】:2020-12-27 12:50:47
【问题描述】:
我有一些这样的 json
const help = [
{
"en": [
{
"test2": [
{
"title": "Naslov1",
"subtitle": "Podnaslov1",
"answers": [
{
"answer": "Odgovor 11"
},
{
"answer": "Odgovor 12"
}
]
}
],
"test1": [
{
"title": "Naslov2",
"subtitle": "Podnaslov2",
"answers": [
{
"answer": "Odgovor 21"
},
{
"answer": "Odgovor 22"
}
]
}
]
}
]
}
]
我需要将此 json 过滤到某个属性,我有属性 en 和 test2 我的新对象应该看起来像
const newArray = [ {
"title": "Naslov1",
"subtitle": "Podnaslov1",
"answers": [
{
"answer": "Odgovor 11"
},
{
"answer": "Odgovor 12"
}
]
}]
我已尝试 help.en.test2,但出现错误 TypeError: Cannot read property 'test2' of undefined
谁能帮我重新映射一下,谢谢
【问题讨论】:
-
这些都是数组,你试过
help[0].en[0].test2[0]吗?
标签: javascript json angular typescript