Last active
May 13, 2022 13:20
-
-
Save JohnMarkT/c8fc9b2141fff2b9fdfb4e64d1fd8adf to your computer and use it in GitHub Desktop.
get deeply nested property
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 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