Answers for "how to get sum of an array in js"

27

array sum javascript

const arr = [1, 2, 3, 4];
const sum = arr.reduce((a, b) => a + b, 0);
// sum = 10
Posted by: Guest on January-26-2021
3

sum all elements in array javascript

arr.reduce((a, b) => a + b)
Posted by: Guest on June-27-2020
0

how to find the sum of array using JavaScript

// If you do not want to use array.reduece you can itereate through the array and then get the solution.
const  getSum = (arr)=>{
  let sum = 0;
  for(key of arr){
    sum += key
  }
  return sum
}
Posted by: Guest on October-03-2021

Code answers related to "how to get sum of an array in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language