js array sum
const arr = [1, 2, 3, 4];
const sum = arr.reduce((a, b) => a + b, 0);
// sum = 10const sum = arr => arr.reduce((a, b) => a + b, 0);const arrSum = arr => arr.reduce((a,b) => a + b, 0)arrSum = function(arr){ return arr.reduce(function(a,b){ return a + b }, 0);}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 722console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)
Also in JavaScript:
- c# get json object from the immediate window?
- javascript foreach get key and value
- jason rpc reactjs
- what is node.js
- .shift js
- a open in new tab
- json placholder
- Syntax Error: Thread Loader (Worker 0) .eslintrc.js: Environment key "es2021" is unknown at Array.forEach (<anonymous>)
- js detect all images errors
- array index javascript show only first 2 elements
- jquery wrap inner text
- edit json via nodejs
- jquery datatable draw false
- go to next route vuejs
- javascript loop through arrya
- Property 'find' does not exist on type NodeListOf
- vue v-for object
- react js download file
- javascript detect touch
- Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.ts(1219) angular
- angular two datepickers
- jest mock mockname
- airbnb react native eslint
- output angular