二维数组遍历
-
二维数组:数组本身还是一个数组
-
二维数组遍历:先遍历外部数组,内部遍历数组元素(还是数组)
-
一般情况下:我们都是直接遍历外部(元素个数不确定),而内部通常是直接取(数据明确长度,且有规范)
代码
-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
/*
第一行 i= 1 ,列数 1
第二行 i= 2 ,列数 2
第三行 i= 3 ,列数 3
^^^
i = 9 ,列数 9
内层循环次数 = i
*/
//1.外层循环 : 行 9
for(let i = 1;i<=9;i++){
//2.内层循环次数 = i
for(let j = 1;j<=i;j++){// i = 9 j = 1 2 3 4 5 6 7 8 9
document.write(j + '*' + i + '=' + j*i + ' ');
};
document.write('<br><br>');
};
</script>
</body>
</html>
效果图