Hi, new to this forum so hi to all
I am stuck when trying to total the elements in an array, I keep getting NaN and cannot for the life of me see what I am doing wrong.
I am using a prototype function:
Array.prototype.sum = function(){
var totalSum:Number,a=0;
while(a<this.length){
totalSum+=this[a];
a++;
}
return totalSum;
}
var testArray:Array=Array(5,5,5,5,5,5,5,5,5,5);
trace(testArray.sum());
this gives me NaN
any help most appreciated!