天涯蝶舞
2016-07-08 17:52
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>流程控制语句</title>
<script type="text/javascript">
//第一步把之前的数据写成一个数组的形式,定义变量为 infos
var gril=new Array()
var stu=[["小A","女",21,"大一"],["小B","男",23,"大三"],["小C","男",24,"大四"],["小D","女",21,"大一"],["小E","女",22,"大四"],
["小F","男",21,"大一"],["小G","女",22,"大二"],["小H","女",20,"大三"],["小I","女",20,"大一"],["小J","男",20,"大三"]];
document.write("stu:"+stu.length+"<br>");//总的学生数量
//第一次筛选,找出都是大一的信息
for(var i=0;i<stu.length;i++){
switch (stu[i][3]){
case "大一":
gril[i]=stu[i];
document.write("大一的学生有:"+stu[i]+"<br>");
break;
}
}
document.write("gril:"+gril.length+"<br>");//大一的学生数量
//第二次筛选,找出都是女生的信息
for(var j=0;j<gril.length;j++){
switch (gril[j][1]){
case "女":
document.write("大一的女学生有:"+gril[j][0]+"<br>");
break;
}
}
</script>
</head>
<body>
</body>
</html>
原来要把gril[i]=stu[i];改成gril[gril.length]=stu[i];因为当i=9时,gril中虽然gril[3]、gril[7]。。。。。。没有数据,但是gril的长度也会变成9.
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题