Last active
August 31, 2016 17:00
-
-
Save banjeremy/ded65f283bbf58d1b016a7785323d656 to your computer and use it in GitHub Desktop.
Retrieve deeply nested object properties by string
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
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