Skip to content

Instantly share code, notes, and snippets.

@OzieWest
Created November 25, 2016 15:13
Show Gist options
  • Select an option

  • Save OzieWest/58ea3c4c03af3ddd6623dac464731484 to your computer and use it in GitHub Desktop.

Select an option

Save OzieWest/58ea3c4c03af3ddd6623dac464731484 to your computer and use it in GitHub Desktop.
Accessing nested JavaScript objects with string key
function resolve (path, obj) {
return path.split('.').reduce((prev, curr) => {
return prev ? prev[curr] : undefined;
}, obj)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment