Skip to content

Instantly share code, notes, and snippets.

@boh1996
Created July 11, 2012 15:36
Show Gist options
  • Save boh1996/3091206 to your computer and use it in GitHub Desktop.
Save boh1996/3091206 to your computer and use it in GitHub Desktop.
Set object by path value
/**
* @author devman
*/
function setObjectPathValue(source, path, value) {
var parts = path.split('.'), len = parts.length, target = source;
for (var i = 0, part; i < len - 1; i++) {
part = parts[i];
target = target[part] == undefined ? (target[part] = {}) : target[part];
}
target[parts[len - 1]] = value;
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment