javascript sum array of objects
arr = [{x:1}, {x:3}]
arr.reduce((accumulator, current) => accumulator + current.x, 0); run.addEventListener("click", function () {
let sum = people.reduce(function (a, b) { // function(previousValue, currentValue)
return {
age: a.age + b.age, //select age in object array
};
});
console.log(sum); //output sum of ages
});const fruitTally = fruit.reduce((currentTally, currentFruit) => {
currentTally[currentFruit] = (currentTally[currentFruit] || 0) + 1
return currentTally
} , {})
// returns {"apple":3,"banana":3,"cherry":2,"mango":2,"apricot":1,"guava":2}
Also in JavaScript:
- regex to get part of word nodejs
- document getelementsbyclassname not getting all elements
- is nodejs code visible client side
- readfile nodejs
- To set the text of button using Jquery
- javascript add class
- get data from column in table js
- classname toggle js
- agrgar atributo con id jquey
- console.log
- Rounding Up To The Nearest Hundred js
- javascript get hour from date
- set and get array inside cookie in javascript
- javascript callback function
- input radio trigger select jquery
- convert timestamp to date js
- mysql json_array_append
- how to add objects in array in javascript
- materialize for react
- (node:14372) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
- SQL Developer store procedure insert json file to blob
- javascript get data attribute value
- w3 js resize event
- setinterval vs settimeout in javascript\