此问题在此处已有答案:
Filter array of objects based on another array in javascript(共10个答案)
6小时前关门了。
我有一个对象数组和一个整数id数组。
我只想在react jsx中拥有id与array匹配的对象数组中的那些条目。
例如:
A = [(0)-> id:'123', name:'john', city:'Newyork']
[(1)-> id:'345', name:'martin', city:'Tokyo']
[(2)-> id:'456', name:'lee', city:'Malbonre']
[(3)-> id:'567', name:'roman', city:'Delhi']
[(4)-> id:'789', name:'julie', city:'US']
B = [123, 456,567]
我希望得到这样的结果:数组A应该只有
A = [(0)-> id:'123', name:'john', city:'Newyork']
[(1)-> id:'456', name:'lee', city:'Malbonre']
[(2)-> id:'567', name:'roman', city:'Delhi']
2条答案
按热度按时间vlju58qv1#
将
filter
与includes
一起使用o4tp2gmn2#
https://codesandbox.io/s/new?file=/src/App.js:56-421