0

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.

4

1 回答 1

2

您的 push() 方法似乎将一个对象推送到您的数组中,因此 GPA_Array[0][1] 可能会引发异常。将数组中的每个项目视为一个对象并使用对象表示法,您应该能够通过以下方式访问它:

Object gpaEntry = GPA_Array[0];
trace("gpaEntry {Num:" + gpaEntry.Num + ",Course:" + gpaEntry.Course + ",Grade:" + gpaEntry.Grade + ",Credits:" + gpaEntry.Credits + "});
于 2012-09-26T19:38:06.897 回答