Skip to content

Instantly share code, notes, and snippets.

@cubicleWar
Last active October 27, 2017 03:38
Show Gist options
  • Save cubicleWar/d8855d2c49e6584f5561 to your computer and use it in GitHub Desktop.
Save cubicleWar/d8855d2c49e6584f5561 to your computer and use it in GitHub Desktop.
Read nested a nested property from an object given a key sequence string like 'location.x.elevation'
function readNested(obj, keys)
{
var parts = keys.split('.'),
curr = obj;
for (var i = 0; i < parts.length; i++)
{
if (!curr[parts[i]])
{
return null;
}
curr = curr[parts[i]];
}
return curr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment