天很藍霧霾終會散_0
2019-02-09 12:45
var infos =
[
['小A','女',21,'大一'],['小B','男',23,'大三'],
['小C','男',24,'大四'],['小D','女',21,'大一'],
['小E','女',22,'大四'],['小F','男',21,'大一'],
['小G','女',22,'大二'],['小H','女',20,'大三'],
['小I','女',20,'大一'],['小J','男',20,'大三']
]
document.write("筛选出的大一女生:<br />");
for(var i=0;i<infos.length;i++) {
if (infos[i][3]=="大一" && infos[i][1]=="女" )
{
document.write(infos[i][0]+"<br />");
}
}
运行了一下你的代码,是可以的,没修改任何东西
你的数组定义有误,把里面的单引号改为双引号
可以同时筛选
var infos=[["小A","女",21,"大一"],["小B","男",23,"大三"],["小C","男",24,"大四"],["小D","女",21,"大一"],["小E","女",22,"大四"],["小F","男",21,"大一"],["小G","女",22,"大二"],["小H","女",20,"大三"],["小I","女",20,"大一"],["小J","男",20,"大三"]];
for(var i=0;i<infos.length;i++){
if(infos[i][1]=="女"&&infos[i][3]=="大一"){
document.write("大一女生有:"+infos[i][0]+"<br/>");
};
};
因为问题是两问啊...两次筛选两个问题
JavaScript进阶篇
468190 学习 · 21891 问题
相似问题
回答 3
回答 2
回答 5
回答 4
回答 1