Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Last active August 29, 2015 14:16
Show Gist options
  • Save danielmackay/291756d7802541f79203 to your computer and use it in GitHub Desktop.
Save danielmackay/291756d7802541f79203 to your computer and use it in GitHub Desktop.
Javascript function to dynamically index though an object based on a string index
function (target, field) {
var path
if (field) {
path = field.split('.');
path.forEach(function (key) {
if (target && target[key]) {
target = target[key];
}
});
}
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment