Skip to content

Instantly share code, notes, and snippets.

@leandrojo
Created December 5, 2017 14:33
Show Gist options
  • Select an option

  • Save leandrojo/1dd2cfd276013b82de2f8a542c7e76ea to your computer and use it in GitHub Desktop.

Select an option

Save leandrojo/1dd2cfd276013b82de2f8a542c7e76ea to your computer and use it in GitHub Desktop.
/**
* @param {*} obj - Objeto a ser rastreado.
* @param {*} key - Percurso a ser traçado.
*
* Exemplo:
* const 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