views:

15

answers:

2

Hi,

I have following kind of index while accessing json data using jquery

data.rows[0].student_1
data.rows[0].student_2
data.rows[0].student_3 and so on...

Now, i want to automate this thing in a loop like

for(var i=1;i<length;i++)
{
  // so that i can access all student records i.e. student_1, student_2 and so on
 data.rows[0].student_+i; // this doesn't work

}
+1  A: 

Use the array style property accessor:

data.rows[0]["student_"+i];
Andy E
A: 

You can use square brackets:

for(var i=1;i<length;i++)
{
 data.rows[0]['student_'+i];
}

see also here: http://24ways.org/2005/dont-be-eval

mamoo
Its working !! thanks
hunt