reduce

Returns an aggregated value derived from applying the function parameter successively to each value in array in combination with the result of the previous application of the function.

reduce

Returns an aggregated value derived from applying the function parameter successively to each value in array in combination with the result of the previous application of the function.

Type: transform

Aliases

arrayReduce, reduce

Parameters

  • input (array): The input array to reduce.
  • expression (string): The JEXL expression to apply for each reduction step.
  • initialValue (unknown): The initial value for the accumulator.

Returns

Type: unknown

The final accumulated value, or undefined if input is not an array.

Examples

reduce([1, 2, 3, 4], "accumulator + value", 0) // 10
[1, 2, 3]|reduce("accumulator * value", 1) // 6
reduce(["a", "b", "c"], "accumulator + value", "") // "abc"
Cookie Notice

We use cookies to enhance your browsing experience.