0

Question: How can I create an (empty) object whereas the name of the object itself shall be created dynamically based on a constructed string as the object name. Is that even possible?

So far I tried to find solutions to this questions but most questions refer to how to dynamically add/change keys of an object.

What it should do is actually let `text${myVar}` = {}; where text${myVar} shall be the name of the object taking into account the variable myVar. So I actually want to solve programmatically what I would do manually in case text${myVar} would be equal to dataQ25 and creating an object with let dataQ25 = {};

Thanks a lot!

  • Need to add that ```myVar``` is a string itself. – SimonTheSorcerer Jul 03 '22 at 11:37
  • 1
    This sounds like an [XY problem](https://xyproblem.info/). Why do you need the name to be dynamic? This is a very unusual thing to do, especially since the next logical question will then be "how do I access a variable with dynamic name". Why not creating an object that holds those different values, and use object keys? Please describe the actual problem you are trying to solve with this. – CherryDT Jul 03 '22 at 11:40
  • how will you refer to `let dataQ25` later in code, if you don't know the variable name? – GrafiCode Jul 03 '22 at 11:41

0 Answers0