Click to See Complete Forum and Search --> : Variable Variables in JavaScript


VanZylKruger
01-06-2003, 12:40 PM
I am trying to add a counter part to the end of a variable. Here is the pseudo code:

for (i=1;i<=20:i++){

temp&i=temp&i+1;}

Here I used the & for the variable concatenation. This doen not work in JavaScript. Is there another way????

gil davis
01-06-2003, 12:47 PM
I am not familiar with "variable concatenation". What is it supposed to do?

VanZylKruger
01-06-2003, 01:16 PM
Because javascript cannot handle integers as variable names I want to add some text infront of numbers and create a variable name i.e.

Temp (variable 1)
1 (counter variable)

When I put them together it creates i new variable Temp1.

No if you have a loop you can create a number of variables with the same properties.

i = 1 to 2

Thus you will get Temp1 and Temp2.....

Charles
01-06-2003, 01:19 PM
This is one of those very rare cases where the eval function is useful. See http://developer.netscape.com/docs/manuals/js/client/jsref/toplev.htm#1063795 but know that you might be better off simply using an array.