Table of Contents

Java Script Reduce function

reduce is a method that applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

This can be very useful for tasks such as summing all the values in an array or reducing an array of objects into a more useful structure.

Here's the general syntax:

array.reduce(callback[, initialValue])

Callback

This is the function to execute on each element in the array, taking four arguments:

Initial Value

initialValue - (Optional) Value to use as the first argument to the first call of the callback.