二维数组就要进行for嵌套循环两次,以此类推,三维就循环三次,只要充分理解for循环,问题就不难解决
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var list = [
[1,3,5],
[2,4,6],
[3,6,9]
]
var sum = 0;
for (var k = 0; k < 3; k++) {
for (var i = 0; i < 3; i++){
sum += list[k][i];
}
}
document.write(sum);
</script>
</body>
</html>