1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Array.prototype.reduce in JavaScript by example

    javascriptJavaScript

    Let's take a closer look at using Javascript's built in Array reduce function. Reduce is deceptively simple and when harnessed correctly can achieve very powerful results. By leveraging reduce, we can answer a variety of questions on a single, simple data set. In this lesson, we'll look at how you might use Array.prototype.reduce to:

    • Sum an array of numbers
    • Reduce an array of objects to a sum of a given property
    • Group an array of objects by key or a set of given criteria
    • Count the number of objects in an array by key or a given set of criteria