Trying to interpretate your question, this may be a solution to what you are looking for:
function createNestedProperties(obj, array, value) {
var result = {};
var result_tmp = obj;
var i = 0;
while (i < array.length) {
if (i < (array.length - 1))
result_tmp[array[i]] = {};
else
result_tmp[array[i]] = value;
result_tmp = result_tmp[array[i]];
i++;
}
return obj;
}
used this way:
var main_obj = {"value1":{"value2":{"value3":{}}}};
var dynamic_array = ["value1", "value2", "value3"];
main_obj = createNestedProperties(main_obj, dynamic_array, {"value_Z":"new value"});
Resulting object:
{"value1":{"value2":{"value3":{"value_Z":"new value"}}}}
This function would override existing properties in main_obj if already there.
main_obj[dynamic_array[0]]etc... ?