DEV Community

Justin
Justin

Posted on

JS Challenge: Sum of the values of an object's properties

Steps involved:

  1. Get the object's values into an array using Object.values()
  2. Use Array.prototype.reduce() to find the sum of the values
expenses = {grocery: 23.45, cleaners: 17.88, uber: 12.25, tip: 2.00}
Object.values(expenses).reduce((total, value) => 
  total + value, 0
) //returns the sum of values -> 55.58
Enter fullscreen mode Exit fullscreen mode

Top comments (0)