我必须按键的值比较 2 个数组。如果“links”数组中的“target”或“source”不是“nodes”数组中的“id”之一,则必须从“links”中删除相应的数组。
从:
{
"nodes":[
{
"id": b,
"year": 3
},
{
"id": c,
"year": 1
},
{
"id": d,
"year": 2
}
],
"links":[
{
"source": a,
"target": b
},
{
"source": a,
"target": c
},
{
"source": b,
"target": a
}
{
"source": c,
"target": d
}
]
}
结果:
{
"nodes":[
{
"id": b,
"year": 3
},
{
"id": c,
"year": 1
},
{
"id": d,
"year": 2
}
],
"links":[
{
"source": c,
"target": d
}
]
}
如果有人可以帮助我用 javascript 解决这个问题,那就太好了。