newMember
newMember

Reputation: 41

Trouble accessing Array Elements

I'm creating this array.

var GPA_Array:Array=new Array();



var dg:DataGrid= new DataGrid();

gpaBuild();

            function gpaBuild()
            {

                dg.columns=["Num","Course","Grade","Credits"];


                GPA_Array.push({Num:"1",Course:"ADS",Grade:"A+",Credits:"4"});
                GPA_Array.push({Num:"1",Course:"ADD",Grade:"A+",Credits:"4"});
                dg.dataProvider=new DataProvider(GPA_Array);    



            }

after pushing data in the array ,i need to accees Grade and credits. I have tried this method,

GPA_Array[0][1],GPA_array[0][2] ,

but it didn't work. If i try to trace it

 trace(GPA_Array[0][1])

it gives me undefined . also ,when i use trace(GPA_array.toString), it gives me error.

Upvotes: 0

Views: 50

Answers (1)

codewrangler
codewrangler

Reputation: 350

Your push() method appears to be pushing an object into your array, so GPA_Array[0][1] will likely throw an exception. Treating each item in the array as an object and using object notation, you should be able to access it with something like:

Object gpaEntry = GPA_Array[0];
trace("gpaEntry {Num:" + gpaEntry.Num + ",Course:" + gpaEntry.Course + ",Grade:" + gpaEntry.Grade + ",Credits:" + gpaEntry.Credits + "});

Upvotes: 2

Related Questions