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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With