循环遍历多维数组jquery

时间:2012-06-25 13:30:48

标签: php javascript jquery

我从php函数返回的数据如下:

data[0]
     [0]
       <table>
        ....
       </table>
     [1]
       <table>
        ....
       </table>
       .
       .
       .etc
 data[1]

如何通过javascript循环遍历此数组!

1 个答案:

答案 0 :(得分:5)

可以使用嵌套的jQuery foreach function.

$.each(data, function(key, value) { 
  //this is each data... data[0], data[1]... etc, the value being value and the index being key.
  $.each(key, function(innerKey, innerValue){
    //this is where your tables are. innerKey being the index innerValue being the value.
    <table>
    ...
    </table>
  });
});