Как, имея массив ключей, достучаться до соответствующего им вложенного свойства:
const nested = {
_keys: arr => arr
.flat(Infinity)
.flatMap(n => typeof n === 'string' ? n.split('.') : n),
get(obj, ...args) {
return nested._keys(args).reduce((p, c) => p?.[c], obj);
},
set(obj, ...args) {
const val = args.pop();
const keys = nested._keys(args);
const key = keys.pop();
return keys.reduce((p, c) => p[c] ??= {}, obj)[key] = val;
},
};
В вашем случае применять так:
nested.set(this.data, args, value);.
А вообще, ключи можно указывать в довольно-таки произвольном виде, например:
nested.get([], 'constructor.prototype', [ 'at', [[[ 'name' ]]] ], 'length') // 2