<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type="text/javascript"> var infos=[ ['小A','女',21,'大一'],['小B','男',23,'大三'],['小C','男',24,'大四'],['小D','女',21,'大一'],['小E','女',22,'大四'],['小F','男',21,'大一'],['小G','女',22,'大二'],['小H','女',20,'大三'],['小I','女',20,'大一'],['小J','男',20,'大三']]; var arr1=new Array(); var n=0; for(i=0;i<infos.length;i++){ if(infos[i][3]=="大一"){ arr1[n]=infos[i]; document.write(arr1[n]+"<br/>"); n=n+1; } } document.write("大一人数: "+arr1.length+"<br/>"); for(i=0;i<arr1.length;i++){ switch(arr1[i][1]){ case '女': document.write(arr1[i]+"<br/>"); n=n+1; } } </script> </head> <body> </body>
将遍历得到的结果放到数组arr1中