var sum = 0 ; for(var i=0;i<=strarr.length;i++){ sum = sum + parseInt(strarr[i].substr(strarr[i].indexOf(":")+ 1)); } document.write(fullyear + "年" + fullmonth + "月" + fullday +"日" + " " +day +"班级平均分为:" + sum/strarr.length); 大神们,我这哪里错了?不能输出
i<=strarr.length这里错了是i<strarr.length,否则数组越界
i<=strarr.length改为i<strarr.length试试