array sum javascript
const arr = [1, 2, 3, 4];
const sum = arr.reduce((a, b) => a + b, 0);
// sum = 10console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)const sum = arr => arr.reduce((a, b) => a + b, 0);[1, 2, 3, 4].reduce((a, b) => a + b, 0)
// Output: 10const arrSum = arr => arr.reduce((a,b) => a + b, 0)arrSum = function(arr){ return arr.reduce(function(a,b){ return a + b }, 0);}
Also in JavaScript:
- javascript get day of year
- jquery remove keypress event
- infinite scrolling firestore vuejs
- javascript math absolute
- json traversal in js
- how to delete a line in vs code
- javascript string concat vs +
- Exception in thread "main" org.openqa.selenium.JavascriptException: cannot read getPlayerState
- javascript foreach key value
- js variable
- select first option in dropdown jquery
- how to create server.js file
- javascript all type of data
- javascript is number an integer
- js array of strings mongoose
- length of array javascript
- How to pass a map from controller to javascript function in VF page
- react jsx style with calc
- javascript count digits
- filter even numbers javascript
- javascript how to raise the error
- function to create an element javascript
- javascript location redirect
- vuejs cant add script in template