Im creating a filtration in the E-commerce project. I have data like
const gender = ["male"]
const brand = ["adidas","nike"]
const price =[100]
//note: gender,brand,price are not static array, it can single element or more than that.
const allProducts = [
{brand:"puma",gender:"male",price:50},
{brand:"nike",gender:"male",price:90},
{brand:"adidas",gender:"female",price:110},
{brand:"adidas",gender:"male",price:95},]
Now, I want to filter all products based on gender, brand, and price. I should get all the products having gender male with brand Adidas and Nike and price less than 100.
I have achieved the result for the brand alone, like this
const[filteredprod,setFilteredprod]=useState()
allProducts.forEach((value)=>{
for(var i=0;i<brand.length;i++){
if(value.brand===brand?.[i])
{setFilteredProd = value
)}}
})
But I want to do to brand gender price simultaneously and get the product. How can I do that? Thanks!!