为了账号安全,请及时绑定邮箱和手机立即绑定

这样子用if为什么输不出数据

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>");

                

            }

            

        }

    }

   


正在回答

2 回答

你的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 />");
             }
          }
        }
    }

0 回复 有任何疑惑可以回复我~
#1

慕姐7545903 提问者

非常感谢!谢谢小姐姐
2017-11-22 回复 有任何疑惑可以回复我~

···

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

这样子用if为什么输不出数据

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信