我是编码新手,正在试图弄清楚为什么这不起作用。该函数工作正常我假设 sumArray 函数中存在未处理的基本缺陷
// SET UP FUNCTIONS FOR LATER USE
// sumArray - takes all values within an array and adds them
var sumArray = function(x){
var sum = 0;
for(i=0;i<x.length;i++) {
sum += parseInt(x[i]);
};
return sum;
};
// create an array and use sumArray function inside of a loop.
// This works
var arrayTest = new Array(1,2,3,4,5,6,7,8,9,10);
document.write (sumArray(arrayTest);
// This crashes the browser
for(i=0;i<10;i++){
document.write("<br/>" + sumArray(arrayTest) + "<br/>");
};
提前感谢您的任何见解。