Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Last active April 26, 2024 23:04
Show Gist options
  • 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