Compare objects in two arrays and return based on match in javascript

后端 未结 3 632
梦谈多话
梦谈多话 2021-01-29 00:34

I am using React for this, but the concept is in javascript. So hopefully I can leave React code out for simplicity sake.

I have two arrays that I need to filter out. My

3条回答
  •  自闭症患者
    2021-01-29 01:11

    You could use filter on the first array ,and includes on the second array:

    arr1
      .filter(e => arr2.map(e2 => e2.id).includes(e.id))
      .map(e => return (
    Match
    ));

提交回复
热议问题