Reputation: 93
I'm using for()
to loop a function. In this function, you need to have different variable to specific which container will be update.
When loop, the variable will use string+count integer to have different var name. Example: t=1 > var title1
, t=2 > var title2
etc.
Example code:-
for(t = 1; t <= 5; t++) {
var title(t) = function(e){}
}
If I use var var title+t = function(e){}
, its not working.
Hope any one can help me on this.
Upvotes: 0
Views: 61
Reputation: 1849
Arrays let you store multiple values and refer to them by an index number. For example:
var title=[];
for (var t=0; t<=4; t++) {
title[t] = //something
}
You can then use an index like title[2]
to access items in the array. Arrays in Javascript start counting at 0
, so the first item is title[0]
.
Upvotes: 1