Last active
March 11, 2019 20:37
-
-
Save highercomve/8074371a83566c9b1568d0104f1154cf to your computer and use it in GitHub Desktop.
Object path resolution even thought some part get undefined
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 resolve (obj, path, defaultReturn) { | |
| return path.split('.').reduce(function(prev, curr) { | |
| return prev && prev.hasOwnProperty(curr) ? prev[curr] : defaultReturn | |
| }, obj) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment