I am trying to combine a string and number to a dynamiclly generated variable. Currently tried it this way:
const ElementCount = 2;
for (i = 1, i <= ElementCount, i++) {
let SampleVariable[i] = "test";
}
ElementCount will later on be dynamic.
The result of the above function should look like this:
SampleVariable1 = "test"
SampleVariable2 = "test"
My code seems to be wrong - what do I have to change here? Solution can be native JS or jQuery as well.
Thanks a lot!
SampleVariable1is element of array or independent variable?ifstatements or aswitch, or most useful, an array or object to hold the different values.