Skip to content

Instantly share code, notes, and snippets.

@banjeremy
Last active August 31, 2016 17:00
Show Gist options
  • Save banjeremy/ded65f283bbf58d1b016a7785323d656 to your computer and use it in GitHub Desktop.
Save banjeremy/ded65f283bbf58d1b016a7785323d656 to your computer and use it in GitHub Desktop.
Retrieve deeply nested object properties by string
function getNestedProperty(obj, path) {
return path.split('.').reduce(function(prev, next) {
return prev ? prev[next] : undefined;
}, obj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment