Easy Tutorial
❮ Dom Obj Ins Prop Loc Hash ❯

JavaScript reduceRight() Method

JavaScript Array Object

Example

Calculate the sum of array elements:

Output result:

125

Definition and Usage

The reduceRight() method works the same as the reduce() method, but reduceRight() starts accumulating from the end of the array.

Note: reduce() does not execute the callback function for empty arrays.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method Chrome IE Firefox Safari Opera
reduceRight() Yes 9.0 3.0 4 10.5

Syntax

array.reduceRight(function(total, currentValue, currentIndex, arr), initialValue)

Parameters

Parameter Description
function(total, currentValue, index, arr) Required. A function to be run for each element in the array. <br>Function arguments:<br> total<br> Required. The initial value, or the previously returned value of the function.<br> currentValue<br> Required. The current element.<br> currentIndex<br> Optional. The index of the current element.<br> arr<br> Optional. The array object the current element belongs to.
initialValue Optional. A value to be passed to the function as the initial value.

Technical Details

Return Value: Returns the accumulated result.
JavaScript Version: ECMAScript 3

More Examples

Example

Subtract the numbers in the array, starting from the end:


JavaScript Array Object

❮ Dom Obj Ins Prop Loc Hash ❯