Created
March 10, 2016 14:49
-
-
Save L3V147H4N/edcbb8659c2540c421fc to your computer and use it in GitHub Desktop.
Javascript find Deep Value
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 deepFind (path, obj) { | |
var | |
paths = path.split('.'), | |
current = obj || this; | |
for (var i = 0; i < paths.length; ++i) { | |
if (current[paths[i]] == undefined) { | |
return undefined; | |
} else { | |
current = current[paths[i]]; | |
} | |
} | |
return current; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment