Skip to content

Instantly share code, notes, and snippets.

@frostney
Created February 15, 2015 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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