Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript object array sum of values in object

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}
Source by blog.nona.digital #
 
PREVIOUS NEXT
Tagged: #javascript #object #array #sum #values #object
ADD COMMENT
Topic
Name
4+6 =