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 setNested(root, ...args) {
const val = args.pop();
const key = (args = args
.flat(Infinity)
.flatMap(n => typeof n === 'string' ? n.split('.') : n))
.pop();
args.reduce((p, c) => p[c] = p[c] || {}, root)[key] = val;
}const obj = {};
setNested(obj, 'xxx', 'yyy', 'zzz', 69);
setNested(obj, 'xxx.a.b.c', 187);
setNested(obj, [ [ [ '_' ], '?' ], '!' ], 666);