Created
July 31, 2015 03:41
-
-
Save arafeek/856c2f12d24e84fe4f22 to your computer and use it in GitHub Desktop.
Walk a complex object via a path string and mutate a variable
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 set(obj, property, value) { | |
| var properties = R.split('.',property); | |
| var context = obj; | |
| var i; | |
| for(i=0; i < properties.length -1; i++) { | |
| context = context[properties[i]]; | |
| } | |
| context[properties[i]] = value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment