Last active
August 29, 2015 14:16
-
-
Save danielmackay/291756d7802541f79203 to your computer and use it in GitHub Desktop.
Javascript function to dynamically index though an object based on a string index
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 (target, field) { | |
var path | |
if (field) { | |
path = field.split('.'); | |
path.forEach(function (key) { | |
if (target && target[key]) { | |
target = target[key]; | |
} | |
}); | |
} | |
return target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment