How to find a sum of an array in javascript?

How to find a sum of an array in javascript?

function sum(a, b){
var sum = a + b;
returm sum;
}
sum(5,5);

@kishan.chauhan608 ,

find sum of an array [10,20,30,40]

let arr = [1,2,3,4,5,6]
let sum ;
for(let i = 0 ; i < arr.length ; i++){
sum = sum + arr[i];
}
console.log(sum);

1 Like

let arr = [1,2,3,4,5,6]
let sum=0
for(let i = 0 ; i < arr.length ; i++){
sum = sum + arr[i];
}
console.log(“sum:”+sum);

1 Like