Skip to main content
August 22, 2011
Question

how to use var as array name

  • August 22, 2011
  • 1 reply
  • 597 views

i have an array 


var class1:Array = ["hassan","hussein","khaled"]


i want to make new array for each elemet in this array



i try



for(var i = 0 ; i < class1.length ; i++)



{

    var class1:Array = new Array();

}



but i seems wrong



and if i want to use variable as array name

that array name change if var value changed

var class_array_name:String= "class1"

var class_array_name:Array = new Array();

but also seems wrong

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 22, 2011

in the scope of a dynamic class, you can use:

this[class1] = new Array();

August 23, 2011


thanks for your your answer but



why i should use  root[class[1]] every time i  call the newly  made  array


and if i use its new name  "hussein"


compiler said that it isnot defined

kglad
Community Expert
Community Expert
August 23, 2011

that's incorrect and not what i suggested.