You break the path up in to components, then you recursively walk the tree.
My JS is weak, so I'll pseudo code.
path = "go.down.three";
listOfElements = breakUpPath(path); // Now listOfElement = ["go", "down", "three"];
myObj = setObjectValue(myObj, listOfElement, "I'm a value");
function setObjectValue(obj, listOfElements, value) {
var firstPart = pop(listOfElements); // get and remove top of listOfElements stack
if (length(listOfElements) == 0) { // last element of the path, set the value
obj[firstPart] = value;
return obj;
} else {
// check if a property exists at all
var firstValue = obj[firstPart];
if (firstValue == null) {
firstValue = new Object();
obj[firstPart] = firstValue;
}
obj[firstPart] = setObjectValue(firstValue, listOfElement, value);
}
}
So, my as I said, my JS is weak (really weak, I can't really even spell JavaScript). Needless to say, this is untested.
But something like that is what you're looking for. Just work your way down the elements of the path.