我想删除那些refId
id与对象数组的任何id都不匹配的对象σ,如果refId
为空,则不删除它
[
{id: 1 , refId:null, name:'jhon'},
{id: 2 , refId:null, name:'sam'},
{id: 3 , refId:1, name:'fam'},
{id: 4 , refId:2, name:'jam'},
{id: 5 , refId:16, name:'ram'},
{id: 6 , refId:15, name:'nam'}
]
结果:应B:
[
{id: 1 , refId:null, name:'jhon'},
{id: 2 , refId:null, name:'sam'},
{id: 3 , refId:1, name:'fam'},
{id: 4 , refId:2, name:'jam'},
]
2条答案
按热度按时间drkbr07n1#
请使用以下代码尝试一次:
suzh9iv82#
这里有一个树结构,如果树很小,使用过滤器或一些是好的,但如果树很大,你应该尝试用Map(字典)。