multiply arrays javascript 1

multiply arrays javascript

var sum = 0;
for(var i=0; i< arr1.length; i++) {
    sum += arr1[i]*arr2[i];
}

Here is what the above code is Doing:
1. We create a variable called sum and set it to 0.
2. We create a for loop that loops through the length of arr1.
3. We add the current value of arr1 to the current value of arr2 and multiply them together.
4. We add the result to the sum variable.
5. We return the sum variable.

Similar Posts