Created
August 15, 2013 23:40
-
-
Save frostney/6245988 to your computer and use it in GitHub Desktop.
Simple object traversion by dot notation
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
traverseObject = (o, key) -> | |
keyArray = if key.indexOf('.') > 0 then key.split('.') else [key] | |
for k in keyArray | |
return unless Object.hasOwnProperty.call o, k | |
o = o[k] | |
o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment