function setParam() {
switch(arguments.length) {
case 2:
myStorage[arguments[0]]=arguments[1];
break;
case 3:
myStorage[arguments[0]][arguments[1]]=arguments[2];
break;
case 4:
myStorage[arguments[0]][arguments[1]][arguments[2]]=arguments[3];
break;
case 5:
myStorage[arguments[0]][arguments[1]][arguments[2]][arguments[3]]=arguments[4];
break;
default:
throw new Error('Error!');
}
};
function setNestedValue(root, ...args) {
const val = args.pop();
const key = (args = args.join('.').split('.')).pop();
args.reduce((p, c) => p[c] = p[c] || {}, root)[key] = val;
}
const obj = {};
setNestedValue(obj, 'xxx', 'yyy', 'zzz', 69);
setNestedValue(obj, 'xxx.a.b.c', 187);
setNestedValue(obj, '_', 666);