PDA

View Full Version : variable var names


AName
01-11-2006, 01:21 PM
I was wondering if its possible to make the name of an Array varry. Something like this,var i=1;
for(i=1;i>4;i++)
{
var ary+i=new Array('red'+i,'green'+i,'blue'+i);
}
alert(ary3[1]);This would alert "green3", and it would make 3 Arrays, ary1, ary2, and ary3, all with the values of red1,green1,blue1 then red2 and so on. Any ideas on how this would work?

konithomimo
01-11-2006, 05:28 PM
Use a two dimensional array:
function showIt()
{
var myarray = new Array();
var i;
for(i=0;i<4;i++)
{
myarray[i]=new Array('red'+i,'green'+i,'blue'+i);
}
alert(myarray[3][1]);
}

AName
01-12-2006, 07:01 PM
Thanks, that's exactly what I was looking for.

konithomimo
01-13-2006, 04:54 PM
Glad to have been of service.