1var sum = 0;
2for(var i=0; i< arr1.length; i++) {
3 sum += arr1[i]*arr2[i];
4}
5
1The cause is already known. Here's an alternative - using Array.reduce for your method:
2
3console.log( [1, 2, 3].reduce( (a, b) => a * b ) );
4console.log( Array.from( {length: 20} )
5 .map( (v, i) => i + 1 )
6 .reduce( (a,b) => a * b )
7 .toLocaleString());
8
9// for empty arrays, use some initial value
10const arr = [];
11if (arr.reduce( (a, b) => a * b, -1 ) === -1) {
12 console.error(`The given array ${arr} is empty`);
13}