How can I perform an inner join with two object arrays in JavaScript?

后端 未结 7 2005
闹比i
闹比i 2020-12-10 13:56

I have two object arrays:

var a = [
  {id: 4, name: \'Greg\'},
  {id: 1, name: \'David\'},
  {id: 2, name: \'John\'},
  {id: 3, name: \'Matt\'},
]

var b = [         


        
7条回答
  •  生来不讨喜
    2020-12-10 14:38

    If you drop the null criteria (many in the community are saying using null is bad) then there's a very simple solution

    let a = [1, 2, 3];
    let b = [2, 3, 4];
    
    a.filter(x => b.includes(x)) 
    
    // [2, 3]
    

提交回复
热议问题