I have the following JSON (truncated):
{
"** Please contact a mod by posting on the forums **": {
"tvdb_id": "257937",
"last_updated": 1341780286,
"images": {
"poster": "http://zapp.trakt.us/images/posters/17288.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/17288.jpg"
}
},
"Jamies Best Ever Christmas": {
"tvdb_id": "214161",
"last_updated": 1329701153,
"images": {
"poster": "http://zapp.trakt.us/images/posters/9126.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/9126.jpg"
}
},
"Kuromajo-san ga Tooru!!": {
"tvdb_id": "257914",
"last_updated": 1395775431,
"images": {
"poster": "http://zapp.trakt.us/images/posters/15640.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/15640.jpg"
}
},
"Arbesre Shavuout": {
"tvdb_id": "253960",
"last_updated": 1328789472,
"images": {
"poster": "http://zapp.trakt.us/images/posters/14058.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/14058.jpg"
}
}
}
I want to search a value (from a var
for now) and find the key to return the tvdb_id
.
For example if I search for “Jamies Best Ever Christmas” I want to return the respective tvdb_id
.
Would something like this help?
function findKey(obj, value) {
var key;
_.each(obj, function (v, k) {
if (v === value) {
key = k;
}
});
return key;
}
How do I implement it? (JSON newbie)