Filter array of objects with another array of objects

前端 未结 9 1771
小蘑菇
小蘑菇 2020-11-27 05:18

This question is similar to this one Jquery filter array of object with loop but this time I need to do the filter with an array of objects.

Exemple:

I have

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 06:16

    based on @Renato his answer, but shorter:

    const myArray = [{ userid: "100", projectid: "10", rowid: "0" }, ...];
    const myFilter = [{ userid: "101", projectid: "11" }, ...];
    
    const myArrayFiltered = myArray.filter(array => myFilter.some(filter => filter.userid === array.userid && filter.projectid === array.projectid));
    

提交回复
热议问题