Skip to content

Instantly share code, notes, and snippets.

@jhonnymoreira
Last active May 12, 2017 19:25
Show Gist options
  • Save jhonnymoreira/0b6e40070ec663071d7676b60be957ea to your computer and use it in GitHub Desktop.
Save jhonnymoreira/0b6e40070ec663071d7676b60be957ea to your computer and use it in GitHub Desktop.
An oneliner dig function for JavaScript.
/**
* @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