Skip to content

Instantly share code, notes, and snippets.

@frostney
Created February 15, 2015 00:27
Show Gist options
  • Save frostney/e2acfbd98d4a4e9c1024 to your computer and use it in GitHub Desktop.
Save frostney/e2acfbd98d4a4e9c1024 to your computer and use it in GitHub Desktop.
propertyValue: Gets a value from deep/nested objects
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