The reduceRight() method applies a function against an accumulator and each value of the typed array (from right-to-left) has to reduce it to a single value. This method has the same algorithm as Array.prototype.reduceRight(). TypedArray is one of the typed array types here.


typedarray.reduceRight(callback[, initialValue])


Function to execute on each value in the typed array, taking four arguments:
The value previously returned in the last invocation of the callback, or initialValue, if supplied (see below).
The current element being processed in the typed array.
The index of the current element being processed in the typed array.
The typed array reduceRight() was called upon.
Optional. Object to use as the first argument to the first call of the callback.

Return value

The value that results from the reduction.


The reduceRight method executes the callback function once for each element present in the typed array, excluding holes in the typed array, receiving four arguments: the initial value (or value from the previous callback call), the value of the current element, the current index, and the typed array over which iteration is occurring.

The call to the reduceRight callback would look something like this:

typedarray.reduceRight(function(previousValue, currentValue, index, typedarray) {
  // ...

The first time the function is called, the previousValue and currentValue can be one of two values. If an initialValue was provided in the call to reduceRight, then previousValue will be equal to initialValue and currentValue will be equal to the last value in the typed array. If no initialValue was provided, then previousValue will be equal to the last value in the typed array and currentValue will be equal to the second-to-last value.

If the typed array is empty and no initialValue was provided, TypeError would be thrown. If the typed array has only one element (regardless of position) and no initialValue was provided, or if initialValue is provided but the typed array is empty, the solo value would be returned without calling callback.


Sum up all values within an array

var total = new Uint8Array([0, 1, 2, 3]).reduceRight(function(a, b) {
  return a + b;
// total == 6


ECMAScript (ECMA-262)
The definition of '%TypedArray%.prototype.reduceRight' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
reduceRightChrome Full support 45Edge Full support 14Firefox Full support 37IE No support NoOpera Full support 32Safari Full support 10WebView Android Full support 45Chrome Android Full support 45Firefox Android Full support 37Opera Android No support NoSafari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 4.0.0


Full support  
Full support
No support  
No support

See also