programming-examples/js/Array/Write a JavaScript program to compute the sum and product of an array of integers..js
2019-11-15 12:59:38 +01:00

10 lines
223 B
JavaScript

var array = [1, 2, 3, 4, 5, 6],
s = 0,
p = 1,
i;
for (i = 0; i < array.length; i += 1)
{
s += array[i];
p *= array[i];
}
console.log('Sum : '+s + ' Product : ' +p);