So,
I know it is possible to create dynamic keys on an object.
const foo = 'bar';
const obj = {
[foo]: 'this is bar',
};
But is it possible to reference objects by a variable value. For instance if we have 3 objects:
const obj1 = {}
const obj2 = {}
const obj3 = {}
And an array which holds their names
const objects = ['obj1', 'obj2', 'obj3'];
Can we loop through those names and reference their objects. This won't work:
objects.forEach(obj => Object.assign(obj, { extended: true }));
But this will:
objects.forEach(obj => Object.assign(eval(obj), { extended: true }));
But the docs at Mozilla state "Do not ever use eval!"