Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

filter array of objects based on list of values

$
0
0

I have an array as following

array = [{  name: 'A'  instructors: [   {     name:'InsA'   }  ]  businessUnit: {name:'myBusiness'}},{  name: 'B'  instructors: [   {     name:'InsB'   }  ]  businessUnit: {name:'myBusinessB'}}]

I want to filter this array with the values i have which are also in an array as following

nameArr = [A,C,D]instructorArr = [InsA,InsC,InsZ]businessName = [myBusinessB,myBusinessX,myBusinessD]

If can filter this array if i have to check with just one value as following

const filtered = _.filter(groupActivityList, (obj) => {      return (        obj.name === (groupClassFilter !== defaultFilter ? groupClassFilter : obj.name) &&        obj.instructors.length > 0 &&        obj.instructors[0]?.name ===          (groupInstructorFilter !== defaultFilter            ? groupInstructorFilter            : obj.instructors.length > 0 && obj.instructors[0]?.name) &&        obj.businessUnit.name ===          (groupFacilityFilter !== defaultFilter ? groupFacilityFilter : obj.businessUnit.name)      );    });

How do i filter when i have a set of values to filter with Ex: nameArr = [A,C,D]


Viewing all articles
Browse latest Browse all 6287

Trending Articles