Skip to content

Instantly share code, notes, and snippets.

@jalalazimi
Last active February 26, 2018 07:17
Show Gist options
  • Save jalalazimi/c65fcee20991c1cf8ccd08736d449ac5 to your computer and use it in GitHub Desktop.
Save jalalazimi/c65fcee20991c1cf8ccd08736d449ac5 to your computer and use it in GitHub Desktop.
Find property by name in a deep object
function findPropertyInDeepObj(obj, key) {
if (_.has(obj, key))
return [obj];
var res = [];
_.forEach(obj, function(v) {
if (typeof v == "object" && (v = findPropertyInDeepObj(v, key)).length)
res.push.apply(res, v);
});
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment