慕姐7545903
2017-11-20 10:22
var infos=[["小A","女","21","大一"],["小B","男","23","大三"],["小C","男","24","大四"],
["小D","女","21","大一"],["小E","男","23","大三"],["小F","女","24","大四"],["小G","男","23","大一"],
["小H","男","21","大一"],["小I","女","23","大四"],["小J","男","22","大二"]];
for(var i=0;i<infos.length;i++)
{
for(var j=0;j<infos[i].length;j++)
{
if((infos[i][j]=="大一" )&&(infos[i][j]=="女"))
{
document.write("大一女生:"+infos[i]+"<br>");
}
}
}
你的j不可能同时取两个值,假如匹配["小A","女","21","大一"],你的 if((infos[0][3]=="大一" )&&(infos[0][1]=="女")),j值怎么可能在一次循环中即取到3又取到1呢,可以这样
var infos=[["小A","女","21","大一"],["小B","男","23","大三"],["小C","男","24","大四"],
["小D","女","21","大一"],["小E","男","23","大三"],["小F","女","24","大四"],["小G","男","23","大一"],
["小H","男","21","大一"],["小I","女","23","大四"],["小J","男","22","大二"]];
for(var i=0;i<infos.length;i++) {
for(var j=0;j<infos[i].length;j++) {
if(infos[i][j]=="大一" ) { //匹配到大一学生
if(infos[i][1]=="女"){ //再匹配大一学生中的女生
document.write("大一女生:"+infos[i]+"<br />");
}
}
}
}
···
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题