Steps involved:
- Get the object's values into an array using
Object.values()
- 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
Top comments (0)