JavaScript TypedArray reduceRight() Method

The reduceRight function in JavaScript condenses the elements of an array into one single value. The output of this function is held in an accumulator, and each element within the array is processed in a right-to-left fashion to achieve this singular value.

Note: Calling reduceRighton an empty array without an initial value is an error.

Syntax:

Example

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

Parameters:

Total(required): The value that was previously returned by the function.

CurrentValue (Mandatory): The value associated with the current element. M

Index (Optional): The position of the current element within the collection.

Arr(Optional): The reduceRight method was invoked on the array.

InitialValue(Optional): This parameter represents a value that can be supplied to the function to serve as its starting point.

Return value:

Return the reduced single value of the array.

Browser Support:

Chrome Yes
Safari 4
Firefox 3.0
Opera 10.5

Example

JavaScript reduceRight Method

Example

<script>

// JavaScript to illustrate reduceRight() method

// Taking some array as the element of an array "A"

var A = [ ['Java','MongoDB' ], ['python','C'], [ 'RDBMS', 'C++' ] ];

 // Calling array.reduceRight() function

a = A.reduceRight((previousValue, currentValue) => previousValue.concat(currentValue));

 // printing result

document.write(a);

 // expected output: RDBMS,C++,python,C,Java,MongoDB

</script>

Output:

Output

RDBMS,C++, python, C, Java, MongoDB

Input Required

This code uses input(). Please provide values below: