Declare your variable and initialize it as an array
var a = [];
Question
I can't find this answer anywhere. I am learning javascript on myself so I guess this is basic.
I want to assign a variable "count" as the subscript of an array.
var firstnumber = 200;
var count = 1;
var a;
a[count] = firstnumber;
therefore to achieve the result as a[count] = 200
is there anyway to do this?
No correct solution
OTHER TIPS
Declare your variable and initialize it as an array
var a = [];
See the comments below:
var a = new Array(); //create an Array
var count = 0; //arrays start at index 0
var firstnumber = 200;
var secondnumber = 300;
a[count] = firstnumber; //set the first element of the array to firstnumber
count = 1;
a[count] = secondnumber; //set the second element of the array to secondnumber
alert(a[0]); //displays 200 in an alert window
alert(a[1]); //displays 300 in an alert window