问答详情
源自:4-10 编程练习

答案,两种方式实现,仅供参考

<!DOCTYPE  HTML>

<html >

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>流程控制语句</title>

<script type="text/javascript">

  var infos = [["namea","女","25","大一"],["nameb","男","24","大四"],["namec","男","23","大三"],["named","女","24","大一"]];

  

 //第1种方式

 for(var count = 0;count< infos.length;count++){

         //infos[count].indexOf:数组中是否 包含指定字符串

         var isindexOf = infos[count].indexOf("大一");

         var isindexOf2 = infos[count].indexOf("女");

         //结果!-1说明包含 

         if(isindexOf!=-1 && isindexOf2!=-1){//说明包含大一女 

             document.write(infos[count]+"<br/>");

         }

         

     }

//第2种方式

  for(var count2 = 0;count2< infos.length;count2++){

      if(infos[count2][1]=="女" && infos[count2][3]=="大一"){

           document.write(infos[count2]+"<br/>");

      }

  }

 

  

</script>

</head>

<body>

</body>

</html>


提问者:王帅_ 2023-04-11 14:41

个回答

  • 慕移动6432290
    2023-06-01 15:13:51

    <!DOCTYPE  HTML>

    <html >

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title></title>

    <script type="text/javascript">

    var infos = [

        ['小A','女',21,'大一'],

    ['小B','男',23,'大三'],

    ['小C','男',24,'大四'],

    ['小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][3] === "大一" && infos[i][1] === "女") {

    document.write(infos[i][0] + "<br />");

    }

    }

    </script>

    </head>

    <body>

    </body>

    </html>