I want to dynamically initialize a variable array in javascript. I keep getting unexpected token illegal token errors.
in my current script, serviceLimit = 10; but it could be changed at any time.
Attempt #1
var jqSvcPhrase = {};
for(i=1; i<=serviceLimit; i++) {
jqSvcPhrase[+ i +] = ''; // produces - Uncaught SyntaxError: Unexpected token ]
}
Attempt #2
var jqSvcPhrase = {};
for(i=1; i<=serviceLimit; i++) {
jqSvcPhrase\[+ i +\] = ''; // produces - Uncaught SyntaxError: Unexpected token ILLEGAL
}
Attempt #3
var jqSvcPhrase = {};
for(i=1; i<=serviceLimit; i++) {
jqSvcPhrase\\[+ i +\\] = ''; // produces - Uncaught SyntaxError: Unexpected token ILLEGAL
}