Skip to content

Instantly share code, notes, and snippets.

@leandrojo
Created October 6, 2018 20:34
Show Gist options
  • Select an option

  • Save leandrojo/277266ad567b0b761e1a8bed6d14b613 to your computer and use it in GitHub Desktop.

Select an option

Save leandrojo/277266ad567b0b761e1a8bed6d14b613 to your computer and use it in GitHub Desktop.
/**
* @param {*} obj - Objeto a ser rastreado.
* @param {*} key - Percurso a ser traçado.
*
* Exemplo:
* var obj = { a: { b: { c: 100 } } };
* get(obj, 'a.b.c'); // return 100.
*/
export default function Get(obj, key) {
return key.split('.').reduce((o, x) => (typeof o === 'undefined' || o === null ? o : o[x]), obj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment