I need to search an array of objects with an object of search terms and get the index of results in an array.
Let's say I have an array like this:
[
{
name: "Mary",
gender: "female",
country: "USA",
orientation: "straight",
colorChoice: "red",
shoeSize: 7
},
{
name: "Henry",
gender: "male",
country: "USA",
orientation: "straight",
colorChoice: "red",
},
{
name: "Bob",
colorChoice: "yellow",
shoeSize: 10
},
{
name: "Jenny",
gender: "female",
orientation: "gay",
colorChoice: "red",
}
]
Now I need to search the array for:
{
gender: "female"
}
and get result:
[ 0, 3 ]
The search object can be any length:
{
gender: "female",
colorChoice: "red"
}
What's the cleanest and most performant way to search the array?
Thanks.