Skip to content

Instantly share code, notes, and snippets.

@Jberivera
Last active March 13, 2018 20:43
Show Gist options
  • Save Jberivera/83b7393afa69193e156bc52493447e27 to your computer and use it in GitHub Desktop.
Save Jberivera/83b7393afa69193e156bc52493447e27 to your computer and use it in GitHub Desktop.
function getPath (path, obj = {}) {
const [head , ...tail] = Array.isArray(path) ? path : path.split(/\./g)
const value = obj[head]
if (tail.length === 0 || value === undefined) {
return value
}
return getPath(tail, obj[head])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment