Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Created January 11, 2023 01:59
Show Gist options
  • Save Angelfire/f6665839044a08cba7801f25ce7d4bb0 to your computer and use it in GitHub Desktop.
Save Angelfire/f6665839044a08cba7801f25ce7d4bb0 to your computer and use it in GitHub Desktop.
Deep Retrieval
// {
// 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