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)

👋 Kindness is contagious

Explore this practical breakdown on DEV’s open platform, where developers from every background come together to push boundaries. No matter your experience, your viewpoint enriches the conversation.

Dropping a simple “thank you” or question in the comments goes a long way in supporting authors—your feedback helps ideas evolve.

At DEV, shared discovery drives progress and builds lasting bonds. If this post resonated, a quick nod of appreciation can make all the difference.

Okay