Array.reduce_right
Array.reduce_right
Function
Accumulate array elements from right to left.
Syntax
array.reduce_right(callback, initial)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| callback | Fn | No | Empty | The callback signature is fn(acc, value, index, current). |
| initial | Any | No | Last element | Initial accumulated value. |
Return value
| Type | Description |
|---|---|
| Any | Returns the final cumulative value. |
Example
items = ['a', 'b', 'c'] result = items.reduce_right(fn(acc, value) { acc + value }, '') // Output: cba print result
Notes
- An error will be reported when initial is not provided for an empty array.