有一个json:
x = [
{"name":"Peter", "list":[{"position":"high", "id":"ZZ"},
{"position":"low", "id":"KJ"}]},
{"name":"Alise", "list":[{"position":"high", "id":"TC"},
{"position":"low", "id":"ZZ"}]}
]
我需要使用filter()删除“list”中包含“id”:“ZZ”的那些项目。我期望最终的结果如下:
[
{"name":"Peter", "list":[{"position":"low", "id":"KJ"}]},
{"name":"Alise", "list":[{"position":"low", "id":"ZZ"}]}
]
我尝试实现这一目标:
y = for (i=0;i<x.length;++i){
for (n=0;n<x[i]["list"].length;++n){
x[i]["list"][n].filter(id => "id" == "ZZ")
}
}
浏览器控制台输出显示
Uncaught TypeError: x[i]["list"][n].filter is not a function.
你能告诉我如何过滤给定的 json 并摆脱 "id":"ZZ" 行吗?
慕尼黑的夜晚无繁华
繁花如伊
相关分类