二维数组
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>二维数组</title> </head> <body> <script> let score= [ [12,15,78], [76,78.5,79.8], [84.1,85,84]] let total; let max; let min; let avg; for (let i = 0; i <score.length ; i++) { total=0 max=min=score[i][0] for (let j = 0; j<score[i].length; j++) { //score[i].length表示第i个数组里面含有多少个数值; total+=score[i][j]; if(score[i][j]>max) max=score[i][j]; if(score[i][j]<min) min=score[i][j]; } avg=total/score[i].length; let str=`第${i+1}个班的总分为:${total},平均分为${avg},最高分为${max}最低分为${min}` console.log(str) } </script> </body> </html>