Created
January 6, 2014 15:51
-
-
Save unknownuser88/8284791 to your computer and use it in GitHub Desktop.
find in json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getObjects(obj, key, val) { | |
var objects = []; | |
for (var i in obj) { | |
if (!obj.hasOwnProperty(i)) continue; | |
if (typeof obj[i] == 'object') { | |
objects = objects.concat(getObjects(obj[i], key, val)); | |
} else if (i == key && obj[key] == val) { | |
objects.push(obj); | |
} | |
} | |
return objects; | |
} | |
//getObjects(TestObj, 'id', 'A'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment