Reputation: 333
Say I have a simple JavaScript object:
{"omar":"espn.com","omar1":"espn1.com","omar3":"espn.com"}
How do I return all keys that share "espn.com"
without knowing the name of the keys?
In this case, only "omar"
and "omar3"
should be returned.
Upvotes: 3
Views: 2250
Reputation: 60527
Just enumerate the properties with Object.keys
and Array#filter
the ones you want.
var o = {"omar":"espn.com","omar1":"espn1.com","omar3":"espn.com"};
var matched = Object.keys(o).filter(function(key) {
return o[key] === 'espn.com';
});
console.log(matched);
Upvotes: 6