<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>流程控制语句</title>
<script type="text/javascript">
//第一步把之前的数据写成一个数组的形式,定义变量为 infos
var infos=new[['a','女','21','大一'],
['b','男','23','大三'],
['c','男','24','大四'],
['d','女','21','大一'],
['e','女','22','大四'],
['f','男','21','大一'],
['g','女','22','大二'],
['h','女','20','大三'],
['i','女','20','大一'],
['j','男','20','大三']] ;
//第一次筛选,找出都是大一的信息
//第二次筛选,找出都是女生的信息
for(i=0;i<infos.length;i++)
{
if(infos[i][3]=="大一"&&infos[i][1]=="女")
{
document.write(infos[i][0]+"<br>");
}
}
</script>
</head>
<body>
</body>
</html>
var infos=new Array(['a','女','21','大一'],
['b','男','23','大三'],
['c','男','24','大四'],
['d','女','21','大一'],
['e','女','22','大四'],
['f','男','21','大一'],
['g','女','22','大二'],
['h','女','20','大三'],
['i','女','20','大一'],
['j','男','20','大三']
)
该操作呀或者把new去掉
或者 var fons=new Array();
fons=[['a','女','21','大一'],
['b','男','23','大三'],
['c','男','24','大四'],
['d','女','21','大一'],
['e','女','22','大四'],
['f','男','21','大一'],
['g','女','22','大二'],
['h','女','20','大三'],
['i','女','20','大一'],
['j','男','20','大三']];
第一:new删除,因为new是重新定义变量、数组等等;
第二:注意文本中的标点;
正确代码:
<!DOCTYPE HTML> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>流程控制语句</title> <script type="text/javascript"> //第一步把之前的数据写成一个数组的形式,定义变量为 infos var infos=[['a','女','21','大一'], ['b','男','23','大三'], ['c','男','24','大四'], ['d','女','21','大一'], ['e','女','22','大四'], ['f','男','21','大一'], ['g','女','22','大二'], ['h','女','20','大三'], ['i','女','20','大一'], ['j','男','20','大三'] ]; //第一次筛选,找出都是大一的信息 //第二次筛选,找出都是女生的信息 for(i=0;i<infos.length;i++) { if(infos[i][3 ]=== "大一" && infos[i][1] === "女") { document.write(infos[i][0]+"<br>"); } } </script> </head> <body> </body> </html>