Last active
May 12, 2017 19:25
-
-
Save jhonnymoreira/0b6e40070ec663071d7676b60be957ea to your computer and use it in GitHub Desktop.
An oneliner dig function for JavaScript.
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
/** | |
* @function | |
* | |
* Returns the value of a path to be found within an object. | |
* | |
* @param {Object} [from] The object to search | |
* @param {Array} [path] The path to search within object | |
* | |
* @return {*} The value from path search | |
*/ | |
const dig = (from, path) => path.reduce((obj, key) => obj[key], from); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment