Storing Object into an Array
First Method
var Ar:Array=new Array() //Ar is an Array and obj is an object which have two identifiers fname and lname.
var Obj:Object={fname:”Steve”,lname:”Chan”} //Define obj with two identifiers(variables) fname and lname
Ar[0]=Obj // Store obj in Ar at 0 index
trace(Ar[0].fname) //Returns Steve
Second Method
var Ar:Array=new Array({fname:”Steve”,lname:”Chan”}) //Store object in Ar at 0 index
trace(Ar[0].fname) //Returns Steve
Third Method
var Ar:Array=new Array() //Ar is an Array
var Obj:Object={fname:”Steve”,lname:”Chan”} //Define obj with two identifiers(variables) fname and lname
Ar.push(obj) // Pushing (Storing Obj in ar) starts from 0 index
trace(Ar[0].fname) //Returns Steve
Fourth Method
var Ar:Array=new Array() //Ar is an Array
Ar[0].fname=”Steve” //creating an identifier named “fname” in an Array at 0 index.
Ar[0].lname=”Chan” //creating an identifier named “lname” in an array at 0 index
trace(Ar[0].fname) // return Steve |