Created
February 15, 2015 00:27
-
-
Save frostney/e2acfbd98d4a4e9c1024 to your computer and use it in GitHub Desktop.
propertyValue: Gets a value from deep/nested objects
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
var propertyValue = function(obj, key, separator = '.') { | |
var keyArray = key.split(separator); | |
var result = obj; | |
for (var i = 0, j = keyArray.length; i < j; i++) { | |
(function(name) { | |
result = result[name]; | |
})(keyArray[i]); | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment