I wanted to create a basic function summing up values from an array. I'm aware of the array reduce method but i wanted initially to use a loop "for" instead as below...however it returns NaN...why ?
var numbers=[1,2];
var total;
function sum(array){
total=0;
for(var x=0;x<=array.length;x++){
total += array[x];
}
return total;
}
x<=array.length==>x < array.length