I agree - it is possible in JavaScript to use dynamic naming but it is very messy to do so and needing to generally indicates that the original design was wrong.
If you are required to have a list of variables like that, as a learning exercise to help teach you different techniques, then so be it.
If you would like to learn of more appropriate techniques that are easier to work with, please let us know details of what you intend to use it for. We’ll be happy to help.
note that it will only work in legacy JavaScript - once you add ‘use strict’ to indicate modern JavaScript you can’t just add to the global namespace like that as all variables need to be declared before use (plus you shouldn’t be using the global namespace for variables in JavaScript anyway).
Why shouldn’t you use the global namespace for variables? Because it’s entirely possible for other scripts that you run to clobber those variables, resulting in unexpected behaviour.