王帅_
2023-04-11 14:38
<!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","大一"]];
//第一种方式
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/>");
}
}
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>
直接使用 includes 更简单些
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题