sum of number using reduce
console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => 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 722
Also in JavaScript:
- aos
- jquery detect input change
- javascript create object empty
- set auto width sheetjs
- javascript global function
- create moment duration
- json arrays
- formidable form node js
- javascript how to dynamically add asp button
- regex for number and letters
- how to convert date to string in javascript
- generate 50 random numbers between 1 and 500 in javascript
- multi language website angular 6
- adonis attach
- how to count specific letters in string js
- border react native
- javascript es6 dom manipulation
- making js local function globally accessible
- javascript console log
- responsive grid using antd
- react native update state array of objects
- if json then parse
- sort nested data using sort function javascript
- javascript alert