I need to filter an array of items using multiple filter arrays. Output should display only the ones that match all of the selected filters.
for example: Main array contains list of a table
ID TypeID LocationID Name
1 2 16 AB
2 2 22 EF
3 4 75 PQ
4 4 40 MN
5 3 16 AB
And I have three filter arrays:
TypeFilter = [2, 3]
LocationFilter = [22, 16]
NameFilter = ["AB","MN"]
After applying these filters, output should be an object list of this table:
ID TypeID LocationID Name
1 2 16 AB
5 3 16 AB
Thanks
filterfunction for every conditionarr.filter( item => TypeFilter.includes(item.TypeId) && LocationFilter.includes(item.LocationId) && NameFilter.includes(item.Name) ).. However it would be more efficient to store the filters as objects, this way you dont need to do an includes but rather anO(1)lookup on the object key.