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

来源:4-10 编程练习

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

                

            }

            

        }

    }

   


写回答 关注

2回答

  • 彼岸花开灬忆流年
    2017-11-20 11:13:18
    已采纳

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

    慕姐7545...

    非常感谢!谢谢小姐姐

    2017-11-22 12:37:45

    共 1 条回复 >

  • 沐沐幕
    2018-01-13 16:59:05

    ···

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468060 学习 · 21891 问题

查看课程

相似问题