UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ TypedArray/ TypedArray.prototype.reduce()

The reduce() method of TypedArray instances executes a user-supplied "reducer" callback function on each element of the typed array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the typed array is a single value. This method has the same algorithm as Array.prototype.reduce.

Syntax

reduce(callbackFn)
reduce(callbackFn, initialValue)

Parameters

Return value

The value that results from running the "reducer" callback function to completion over the entire typed array.

Exceptions

Description

See Array.prototype.reduce for more details. This method is not generic and can only be called on typed array instances.

Examples

Sum up all values within an array

const total = new Uint8Array([0, 1, 2, 3]).reduce((a, b) => a + b);
// total === 6

Specifications

Browser compatibility

See also