Skip to content

Instantly share code, notes, and snippets.

@dijs
Created April 16, 2017 08:16
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 dijs/6bdd163c236b0266327e356950eacc01 to your computer and use it in GitHub Desktop.
Save dijs/6bdd163c236b0266327e356950eacc01 to your computer and use it in GitHub Desktop.
Get implementation
function get(obj, path, def) {
const parts = path.split('.');
const [first,] = parts;
const value = obj[first];
if (parts.length === 1) {
return value || def;
}
return get(value, parts.slice(1).join('.'), def);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment