I want where the color red and size 4gb just output the exact value but I am getting where size is 4 gb but color is green please help me in this regard. I am making a filter option, and my code is same so please if possible make it my code otherwise you can also suggest how can I achieve this?
const x = [
{
color: "green",
name: "123",
size: "4gb"
},
{
color: "red",
name: "555",
size: "4gb"
},
{
color: "green",
name: "123",
size: "2gb"
},
{
color: "blue",
name: "111",
size: "2gb"
},
{
color: "green",
name: "123",
size: "4gb"
},
{
color: "red",
name: "000",
size: "4gb"
}
]
const op = [{
key: "color",
item: "red"
},
{
key: "size",
item: "4gb"
}];
const fil = x.map(l => op.map(o => l[o.key] === o.item && l)).flat().filter(Boolean);
console.log(fil);
Output should be:
[{
color: "red",
name: "555",
size: "4gb"
},{
color: "red",
name: "000",
size: "4gb"
}];