<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>流程控制语句</title>
<script type="text/javascript">
console.log();
var infos= [
['小A','女',21,'大一'],
['小B','男',23,'大三'],
['小C','男',24,'大四'],
['小D','女',21,'大一'],
['小E','女',22,'大四'],
['小F','男',21,'大一'],
['小G','女',22,'大二'],
['小H','女',20,'大三'],
['小I','女',20,'大一'],
['小J','男',20,'大三']
];
var n=0;
var k=1;
var myarr=new Array();
for(var i=0;i<infos.length;i++){
switch(infos[i]["3"]){
case "大一":
myarr[n]=infos[i];
document.write("这是第"+k+"个"+infos[i]["3"]+"学生:"+myarr[n]+"<br/>");
k++;
n++;
break;
case "大二":
case "大三":
case "大四":
break;
default:
document.write("非大学生不输出!");
}
}
var m=k-1;
document.write("综上,一共有"+m+"个大一学生"+"<br/>");
document.write("下面将筛选出所有大一女生如下:"+"<br/>");
//第二次筛选,找出都是女生的信息
for(var j=0;j<myarr.length;j++){
switch(myarr[j]["1"]){
case '女':
document.write(myarr[j]+"<br/>");
break;
case '男':
break;
default:
document.write("是男生!!");
}
}
m=j-1;
document.write("综上,大一女生一共有:"+m+"个大一学生"+"<br/>");
//document.writ(myarr[j]);
</script>
</head>
<body>
</body>
</html>
输出大一女生哪里有错,因该这样:
var t = 1
for(var j=0;j<myarr.length;j++){
switch(myarr[j]["1"]){
case '女':
document.write(myarr[j]+"<br/>");
t++;
break;
case '男':
break;
default:
document.write("是男生!!");
}
}
m=t-1;
document.write("综上,大一女生一共有:"+m+"个大一学生"+"<br/>");