Skip to content

Instantly share code, notes, and snippets.

@JohnMarkT
Last active May 13, 2022 13:20
Show Gist options
  • Select an option

  • Save JohnMarkT/c8fc9b2141fff2b9fdfb4e64d1fd8adf to your computer and use it in GitHub Desktop.

Select an option

Save JohnMarkT/c8fc9b2141fff2b9fdfb4e64d1fd8adf to your computer and use it in GitHub Desktop.
get deeply nested property
function getByProperty(obj, prop) {
if (typeof obj === "object") {
return Object.keys(obj).reduce( (a, c) => {
if (c === prop) {
a = a.concat(obj[c]);
}
return a.concat(
getByProperty(obj[c], prop) || []
);
}, []);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment