I've been wondering about this for a while, I'm using and setting complex objects in a Redux Store state, and the way I do it is this (proc is an array and mod is the value to set):
if(proc.length > 4) state[proc[0]][proc[1]][proc[2]][proc[3]][proc[4]] = mod
else if(proc.length > 3) state[proc[0]][proc[1]][proc[2]][proc[3]] = mod
else if(proc.length > 2) state[proc[0]][proc[1]][proc[2]] = mod
else if(proc.length > 1) state[proc[0]][proc[1]] = mod
else state[proc[0]] = mod
This allows me to modify an object value with up to 5 levels of nesting, but as you might imagine this code repeats all over the place and it's ugly. I find it hard to believe this is the correct way of doing this, but I have no idea how to search for a better solution. I'm looking for something more like:
state[proc] = mod