开发者

Automate Access of Alpha Numerical index in json

开发者 https://www.devze.com 2022-12-30 10:15 出处:网络
I have following kind of ind开发者_StackOverflow中文版ex while accessing json data using jquery

I have following kind of ind开发者_StackOverflow中文版ex 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

}


Use the array style property accessor:

data.rows[0]["student_"+i];


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

0

精彩评论

暂无评论...
验证码 换一张
取 消