Created
December 5, 2017 14:33
-
-
Save leandrojo/1dd2cfd276013b82de2f8a542c7e76ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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