adding all numbers in an array javascript code example

Example 1: adding numbers in an array javascript

console.log(
  [].reduce((a, b) => a + b)
)

Example 2: javascript sum of array

const sum = arr => arr.reduce((a, b) => a + b, 0);

Example 3: sum of all numbers in an array javascript

const arrSum = arr => arr.reduce((a,b) => a + b, 0)

Example 4: how to add up all numbers in an array

var numbers = [10, 20, 30, 40] 
var sum = 0;
for (var i = 0; i < numbers.length; i++) {  sum += numbers[i]}

Example 5: javascript sum array values

function getArraySum(a){
    var total=0;
    for(var i in a) { 
        total += a[i];
    }
    return total;
}

var payChecks = [123,155,134, 205, 105]; 
var weeklyPay= getArraySum(payChecks); //sums up to 722