Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
Created January 6, 2014 15:51
Show Gist options
  • Save unknownuser88/8284791 to your computer and use it in GitHub Desktop.
Save unknownuser88/8284791 to your computer and use it in GitHub Desktop.
find in json
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