I am trying to filter an object that only returns if the property has all the values within the filtered array. This is the code:
const getFilteredProducts = ()=>{
const filterBrands:string[] = [];
const filterGender:string[] = [];
FilterState().brand.map(brand =>{
if(brand.checked == true){
filterBrands.push(brand.brand);
}
});
FilterState().gender.map(brand =>{
if(brand.checked == true){
filterGender.push(brand.gender);
}
})
products?.map((product)=>{
if(Object.values(product.Brand).includes(filterBrands[0]) && Object.values(product.Gender).includes(filterGender[0])){
console.log(product);
}
})
}
I am firstly looping through the Brand filter and if the filter is ticked it adds it to the brand filter array. E.g- Nike is tick so Nike is added to the filter array. Then I do the same with the gender filter
Then I am looping through the object and I want to check if the object has the brand name that within the array and same with the gender. How can I change the includes(filterBrands[0])
to something that checks all the array? If that makes sense.