I wonder if there is a more elegant way of doing this. Suppose i have an array of objects like this:
a = [
{
\"id\": \"kpi02\",
\"value\": 10
},
Just make use of Array.indexOf
var b = a.filter(function(item){return kpids.indexOf(item.id) > -1 });
Array.indexOf
returns the index of the argument passed in the array on which indexOf
is being called on. It returns -1
if there isn't the element which we are looking for.
So, we make sure that it index is greater than -1