I couldn't find an example here what I'm really looking for. I'd like to multiply all array elements, so if an array contains [1,2,3] the sum would be 1*2*3=6; So far I've got this code, but it returns undefined.
function multiply (array) {
var sum=1;
for (var i=0; i<array.length; i++) {
sum = sum * array[i];
}
return sum;
}
console.log(multiply[1,2,3]);
Could anyone please explain, what am I missing here? Thanks in advance!
See Question&Answers more detail:os