Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Last active August 29, 2015 14:20
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 juliandescottes/2c53afbaed9287de3cb4 to your computer and use it in GitHub Desktop.
Save juliandescottes/2c53afbaed9287de3cb4 to your computer and use it in GitHub Desktop.
getPath
module.exports = function (object, path) {
var parts = path.split ? path.split(".") : path;
try {
var node = object;
parts.forEach(function (part) {
node = node[part];
});
return node;
} catch (e) {
console.error('Failed to get path : ' + path + ' in object : \n' + JSON.stringify(object));
return null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment