![]() |
VOOZH | about |
The reduce() method is used to reduce the collection elements into a single value according to the given callback. It works by passing the result of each iteration to the next one resulting in a single value in the end.
Syntax:
collect(array).reduce(callback)
Parameters: The collect() method takes one argument that is converted into the collection and then reduce() method is applied on it. The reduce() method holds the callback function as parameter.
Return Value: This method returns the reduced value of the collection.
Below example illustrate the reduce() method in collect.js:
Example 1:
Output:
21
Example 2:
Output:
19 253