I want to find out which index(es) in the following array contains an object whose value for the key "id" is x.
var arr1 = [
{
"id":42,
"name":"Object 42"
},
{
"id":99,
"name":"Object 99"
}
]
So for that array, I would want to do this;
findId(arr, 42);
//returns '0'
findId(arr, 99);
//returns '1'
How can I write a function that does that?
This is different than the supposed duplicates, because those duplicates talk about filtering a simple array for a certain value. This question is trying to filter an array of objects where a certain key has a value of x. None of the duplicates solve the problem.