Created
January 11, 2023 01:59
-
-
Save Angelfire/f6665839044a08cba7801f25ce7d4bb0 to your computer and use it in GitHub Desktop.
Deep Retrieval
This file contains 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
// { | |
// prop: { | |
// prop: { | |
// prop: 3 | |
// } | |
// } | |
// } | |
// { | |
// prop: 3 | |
// } | |
// retrieve a prop that is deeply nested within objects | |
// i.e. { prop: { prop: { prop: 3 }}} => 3 | |
function deepRetrieval(obj) { | |
if (typeof obj.prop === 'object') { | |
return deepRetrieval(obj.prop) | |
} else { | |
return obj.prop | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment