Last active
September 16, 2015 13:44
-
-
Save tarzak/0ec11a980fdde5d4b235 to your computer and use it in GitHub Desktop.
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 changeVal (obj, path, val) { | |
var arr = path.split('.'); | |
var object = obj || {}; | |
var tempObj = object; | |
for (var i = 0; i < arr.length - 1; i += 1) { | |
if(typeof tempObj[arr[i]] !== 'object') { | |
tempObj[arr[i]] = {}; | |
} | |
tempObj = tempObj[arr[i]]; | |
} | |
tempObj[arr[i]] = val; | |
return object; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment