Skip to content

Instantly share code, notes, and snippets.

@Amberlamps
Last active August 29, 2015 14:07
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 Amberlamps/1132ef4f5757754964e6 to your computer and use it in GitHub Desktop.
Save Amberlamps/1132ef4f5757754964e6 to your computer and use it in GitHub Desktop.
Resolving dot separated key fields in nested Javascript objects.
function resolveKeyString(obj, keyString) {
return keyString.split('.').reduce(function(p, c) {
return p[c];
}, t);
}
// Usage:
var obj = {
a: {
b: {
c: 'value'
}
}
};
var keyString = 'a.b.c';
console.log(resolveKeyString(obj, keyString));
// => 'value'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment