Created
April 16, 2017 08:16
-
-
Save dijs/6bdd163c236b0266327e356950eacc01 to your computer and use it in GitHub Desktop.
Get implementation
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 get(obj, path, def) { | |
const parts = path.split('.'); | |
const [first,] = parts; | |
const value = obj[first]; | |
if (parts.length === 1) { | |
return value || def; | |
} | |
return get(value, parts.slice(1).join('.'), def); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment