How to use reduce over an array of objects
Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on email

How to use reduce over an array of objects

Another common scenario is computing the total amount of the order. This can be easily achieved using the .reduce() method.
const menuOrder = [
  { name: "Spaghetti", price: 10 },
  { name: "Pizza", price: 8 },
  { name: "Wine", price: 50 },

const totalPrice = menuOrder.reduce((acc, item) => acc + item.price, 0);



Recent Posts

Branding Strategies Guide to Stand Above the Developers Crowd

Do you want to build a personal brand and increase your social media presence as a developer? Then this guide is for you! Learn how to do it today.

30 Useful JavaScript Array Methods You Must Know

If you want to get a deeper understanding of arrays and how they work in your Javascript code, this is the article for you!

Take-Home Coding Challenges: Everything You Need To Know To Ace Them

This blog post will give you the rundown on the do’s and don’ts of take-home coding challenges, as well as some tips to help you ace them!