Using Array.reduce to transform data

The map method is great for creating data that maps directly to elements from an existing array. However, sometimes, the desired result takes on a different shape. To do this, we can use the reduce method to accumulate values into a new form.

In this recipe, we'll take a look at how to use the reduce method to transform data.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.