Filter array of objects with another array of objects

前端 未结 9 1764
小蘑菇
小蘑菇 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:07

    With Ecma script 6.

    const myArrayFiltered = myArray.filter( el => {
      return myfilter.some( f => {
        return f.userid === el.userid && f.projectid === el.projectid;
      });
    });
    

    Function:

    const filterObjectArray = (arr, filterArr) => (
        arr.filter( el =>
            filterArr.some( f =>
                f.userid === el.userid && f.projectid === el.projectid
            )
        )
    );
    
    console.log(filterObjectArray(myArray, myFilter))
    

    Link to example

提交回复
热议问题