Is there a way to dynamically create n variables a_1
, a_2
, a_3
... a_n
, where the value of n is determined during runtime?
Attempting to use the following code would not produce the desired outcome:
var n = prompt("Enter number of variables?");
for (i=0; i<=n; i++) {
var a_i
}
Since the value of n is entered by the user, it's impossible to know in advance how many variables need to be created.
In simple terms, can a variable be named using another variable's value in JavaScript?