Better way to update an object's value at a variable depth
Better way to update an object's value at a variable depth I am working on some software that reads/writes information in localStorage using a handler. You can find a working example here: http://jsbin.com/wifucugoko/edit?js,console localStorage My problem is with the segment of code below ( focusing on the switch statement ): _t.set = function(path, value) { // Update a single value or object if (~path.indexOf(".")) { let o = path.split(".")[0], p = this.get(o), q = path.split(".").slice(1); switch (q.length) { // There has to be a better way to do this... case 1: p[q[0]] = value; break; case 2: p[q[0]][q[1]] = value; break; case 3: p[q[0]][q[1]][q[2]] = value; break; case 4: ...