JAVASCRIPT
array sum javascript
const arr = [1, 2, 3, 4];
const sum = arr.reduce((a, b) => a + b, 0);
// sum = 10
js sum of array
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
// Output: 10
javascript sum of array
const sum = arr => arr.reduce((a, b) => a + b, 0);
how to get sum array in javascript
let sum1 = (arr) => arr.reduce( (x,y) => x+y);
console.log(sum1([2, 4, 9]));
console.log(sum1([15, 200, 18, 0, 18, 18]));
console.log(sum1([100, 4, 17, 29, 81]));
js sum
const array = [1, 2, 3];
const result = array.reduce((accumulator, current) => accumulator + current, 0);
// result === 1 + 2 + 3;
js array elements sum
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
sum of array javascript
const arr = [1,2,3]
const sumOfArr = arr.reduce((a,b) => {
return a + b
})
sum array elements in javascript
console.log(
[1,2,3].reduce(function(acc, val) { return acc + val; })
)
console.log(
[].reduce(function(acc, val) { return acc + val; }, 0)
)
Run code snippetHide results
sum array elements in javascript
console.log(
[1,2,3].reduce(function(acc, val) { return acc + val; })
)
console.log(
[].reduce(function(acc, val) { return acc + val; }, 0)
)
Run code snippetHide results
sum array elements in javascript
console.log(
[1,2,3].reduce(function(acc, val) { return acc + val; })
)
console.log(
[].reduce(function(acc, val) { return acc + val; }, 0)
)
Run code snippetHide results
sum function in javascript
let sum = (...para) => para.reduce((d,b) => d + b);
sum array elements in javascript
console.log(
[1,2,3].reduce(function(acc, val) { return acc + val; })
)
console.log(
[].reduce(function(acc, val) { return acc + val; }, 0)
)
Run code snippetHide results
sum array elements in javascript
console.log(
[1,2,3].reduce(function(acc, val) { return acc + val; })
)
console.log(
[].reduce(function(acc, val) { return acc + val; }, 0)
)
Run code snippetHide results