最近在学习js,之前在上课的时候无论是C++还是java都有学过二维数组,然而宝宝居然不知道二维数组要怎么输出!!!之前是有多渣多混日子啊。。。哎,心碎成了渣渣。。。让我乘热打铁加深下记忆。。。
二维数组必须一行一行输出才能输出二维的你想要的样子,你应该懂得,不然输出的就是所有元素在一行或者直接不显示。举个例子:
var infos =[["小A","女",21,"大一"], ["小B","男",23,"大三"], ["小C","男",24,"大四"], ["小D","女",21,"大一"], ["小E","女",22,"大四"], ["小F","男",21,"大一"], ["小G","女",22,"大二"], ["小H","女",20,"大三"], ["小I","女",20,"大一"], ["小J","男",20,"大三"]]; for(var i=0;i<10;i++){ if(infos[i][1]=="女" && infos[i][3]=="大一"){ //筛选出所有大一女生的信息 for(var j=0;j<infos[i].length;j++){ //遍历一行里的每个元素 document.write(infos[i][j]+" "); //输出一行 } document.write("<br/>"); //输出一行后换行,接着继续遍历下一行 } }
时间: 2024-10-08 15:33:48