Created
December 3, 2012 16:38
-
-
Save acatl/4196153 to your computer and use it in GitHub Desktop.
Parse JS object path that uses dot and bracket 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
parse = (obj, path) -> | |
path = path.split(/[\[\]\.]+/) | |
path.pop() if path[path.length - 1] is "" | |
while path.length and (obj = obj[path.shift()]) | |
; | |
obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any example?