Typed Array reduceRight()
Examples
Subtract the numbers in the array from the last number:
function myFunc(total, num) {
return total - num;
}
// Create a Typed Array
const myArr = Int32Array.of(40, 100, 1, 5, 25, 10);
// Reduce the Array to a Number
let number = myArr.reduceRight(myFunc);
Description
ThereduceRight() method executes a reducer function for each array element.
ThereduceRight() method works from right to left.
ThereduceRight() method returns a single value: the function's accumulated result.
ThereduceRight() method does not execute the function for empty elements.
Note
At the first callback, there is no return value from the previous callback.
Normally, the last array element is used as initial value, and the iteration starts from the element before.
If an initial value is supplied, this is used, and the iteration starts from last element.
See Also:
Syntax
Parameters
| Parameter | Description | ||||||||
| function() | Required. A function to be run for each element in the array. | ||||||||
Reducer function parameters:
| |||||||||
| initialValue | Optional. A value to be passed to the function as the initial value | ||||||||
Return Value
| The accumulated result from the last call of the callback function. |
JavaScript Typed Arrays
Browser Support
typed-array.reduceRight() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers sinceJune 2017:
| Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |

