The https://www.w3schools.com/jsref/jsref_reduce.asp method reduces an array into a single value, but what exactly does that mean, and why is it useful? The reduce() method is similar to the built in https://www.w3schools.com/jsref/jsref_map.asp method but has more built in functionality.

The loop above represented as the reduce method looks like this: Reduce also works when working with an array of objects.

By setting the initial value to an empty array, the reduce function will accumulate values in an array.

Here is an example of the reduce method building an array: And this is an example of how reduce is used to build an array of arrays: A callback can also be passed into an array: Conclusion

Related Articles