TypeScript Array reduceRight() Method Last Updated : 19 Jul, 2024 Comments Improve Suggest changes Like Article Like Report 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]) Parameterscallback: The function to execute on each element in the array. It takes the following arguments:previousValue: The value resulting from the previous call to the callback.currentValue: The current element being processed.currentIndex: The index of the current element being processed.array: The array reduceRight was called upon.initialValue (optional): The initial value to use as the first argument to the first call of the callback.Return Value: This method returns the reduced right single value of the array. Examples of Array reduceRight() MethodExample 1: Reducing an Array to a Single ValueIn this example, we use reduceRight() to subtract all elements of the array from the rightmost element to the leftmost element. JavaScript const array1: number[] = [1, 2, 3, 4, 5]; const result1: number = array1.reduceRight((acc: number, curr: number) => acc - curr); console.log(result1); Output: -3 Example 2: Calculating a Product in Reverse OrderIn this example, reduceRight() is used to calculate the product of all elements in the array, starting from the rightmost element. JavaScript const array2: number[] = [2, 4, 8]; const result2: number = array2.reduceRight((acc: number, curr: number) => acc * curr, 1); console.log(result2); 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. Create Quiz Comment S shubhamsingh10 Follow 0 Improve S shubhamsingh10 Follow 0 Improve Article Tags : TypeScript Explore TypeScript BasicsIntroduction to TypeScript3 min readDifference between TypeScript and JavaScript4 min readHow to install TypeScript ?3 min readHello World in TypeScript2 min readHow to execute TypeScript file using command line?2 min readVariables in TypeScript6 min readWhat are the different keywords to declare variables in TypeScript ?4 min readIdentifiers and Keywords in TypeScript2 min readTypeScript primitive typesData types in TypeScript3 min readTypeScript Numbers4 min readExplain the concept of null and its uses in TypeScript3 min readTypeScript Object typesTypeScript class4 min readHow enums works in TypeScript ?4 min readTypeScript Tuples4 min readTypeScript other typesWhat is any type, and when to use it in TypeScript ?3 min readWhat is an unknown type and when to use it in TypeScript ?3 min readExplain the purpose of never type in TypeScript3 min readTypeScript combining typesTypeScript Union3 min readTypeScript AssertionsExplain Type assertions in TypeScript3 min readTypeScript FunctionsHow to write a function in Typescript ?4 min readHow to achieve function overloading in TypeScript ?2 min readExplain the arrow function syntax in TypeScript2 min readTypeScript toPrecision() Function1 min readTypeScript toFixed() Function2 min readTypeScript toLocaleString() Function2 min readTypeScript toString()1 min readTypeScript interfaces and aliasesWhat are TypeScript Interfaces?4 min readWhat are type aliases and how to create it in Typescript ?3 min readTypeScript classesHow to Extend an Interface from a class in TypeScript ?2 min readHow to Create an Object in TypeScript?4 min readHow to use getters/setters in TypeScript ?5 min readTypeScript Inheritance3 min readWhen to use interfaces and when to use classes in TypeScript ?4 min readGenerics Interface in typescript5 min readHow to use property decorators in TypeScript ?4 min readTypeScript modulesWhat are the Modules in Typescript ?4 min readHow to import a module in Typescript ?5 min read Like