![]() |
VOOZH | about |
The Array.prototype.reduceRight() method is a built-in TypeScript function used to apply a reducer function to each element of the array, processing the elements from right to left, ultimately reducing the array to a single value.
Syntax:
array.reduceRight(callback[, initialValue])
Parameters
Return Value: This method returns the reduced right single value of the array.
In this example, we use reduceRight() to subtract all elements of the array from the rightmost element to the leftmost element.
Output:
-3
In this example, reduceRight() is used to calculate the product of all elements in the array, starting from the rightmost element.
Output:
64The reduceRight() method is a powerful tool for performing reductions on arrays from right to left. It can be used for various operations, such as summing, multiplying, and concatenating elements, making it a versatile method in TypeScript.