JavaScript TypedArray map() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2015

Definition

typedArray.map(callback) calls a function on every element and returns a new typed array with the results. The new typed array has the same type and exactly the same length as the original. Each result is converted to the element type: a Uint8Array wraps numbers above 255, an Int8Array wraps around to negatives, and fractions are cut off. The original typed array is not changed.

Remember
typedArray.map(callback, thisArg)   → new typed array, same type and length

callback(value, index, array)
  result is converted to the element type
  Uint8Array:  300 → 44       Int8Array: 200 → -56
  Uint8ClampedArray: 300 → 255

new Int16Array([150, -20]).map((v) => v * 2)  → 300, -40

Syntax

Pass a function that returns the new value. The second argument thisArg is optional.

JavaScript
typedArray.map(callback)
typedArray.map(callback, thisArg)
CallWhat it does
ta.map((v) => v * 2)Double every element.
ta.map((v, i) => v * i)Use the index in the calculation.
Array.from(ta).map((v) => v / 2)Get a plain Array so the results are not cut to the element type.

Built into JavaScript since ES2015 on all 11 typed array types. On a BigInt64Array the callback must return a BigInt, or a TypeError is thrown.

Library declarations
JavaScript
TypedArray.prototype.map(callbackFn, thisArg?)   // returns a new typed array

// callbackFn(value, index, array) -> the new element value
// result: same type and same length as the original

Parameters

ParameterDescription
callbackA function called once per element with (value, index, array). Return the new value for that position.
thisArgOptional. The value used as this inside the callback. Arrow functions ignore it.

Return Value

Return ValueDescription
New TypedArrayA new typed array of the same type and the same length. Every returned value was converted to the element type.

JavaScript Examples

Example 1 — Double Every Element

An Int16Array of prices in cents is doubled. The new typed array has the same type and the same length.

JavaScript
const cents = new Int16Array([150, -20, 300]);

const doubled = cents.map((v) => v * 2);

console.log(doubled.join(' '));                     // 300 -40 600
console.log(doubled instanceof Int16Array);         // true
console.log(doubled.length + ' of ' + cents.length);  // 3 of 3
console.log(cents.join(' '));                       // 150 -20 300
Try It Yourself

How It Works

  1. One result per element. The callback runs for 150, -20, and 300, and each returned number goes into the same position of the new typed array.
  2. Same type, same length. The result is another Int16Array with three elements, so negative numbers still fit.
  3. The source stays as it was. The last line proves that cents still holds 150, -20, and 300; map() works on a copy.

Example 2 — Results Wrap, Clamp, or Stay Exact

The same math gives different answers on three typed array types. A plain Array keeps the exact result.

JavaScript
const bytes = new Uint8Array([1, 2, 3]).map((x) => x * 100);
console.log(bytes.join(' '));    // 100 200 44

const signed = new Int8Array([100, 50]).map((x) => x * 2);
console.log(signed.join(' '));   // -56 100

const clamped = new Uint8ClampedArray([100, 200]).map((x) => x * 2);
console.log(clamped.join(' '));  // 200 255

const plain = Array.from(new Uint8Array([1, 2, 3])).map((x) => x * 100);
console.log(plain.join(' '));    // 100 200 300
Try It Yourself

How It Works

  1. Uint8Array wraps at 256. The product 300 does not fit in a byte, so it is stored as 300 - 256 = 44.
  2. Int8Array wraps into negatives. The product 200 is above 127, so the signed byte stores -56, while 100 fits and stays.
  3. Clamped stops at 255, Array keeps all. Uint8ClampedArray turns 400 into 255. The plain Array made by Array.from() has no fixed type, so it keeps 300.

Example 3 — Fractions Are Cut Off

Halving odd numbers gives fractions. A Uint8Array can only store whole numbers, so it cuts them off. The callback also uses the index.

JavaScript
const data = new Uint8Array([5, 7, 10]);

const halves = data.map((v) => v / 2);
console.log(halves.join(' '));  // 2 3 5

const plainHalves = Array.from(data).map((v) => v / 2);
console.log(plainHalves.join(' '));  // 2.5 3.5 5

const scaled = data.map((v, i, arr) => v * i + arr.length);
console.log(scaled.join(' '));  // 3 10 23
Try It Yourself

How It Works

  1. The decimal part is dropped. The results 2.5 and 3.5 are stored as 2 and 3, because a Uint8Array holds only whole numbers.
  2. A plain Array keeps decimals. Mapping over Array.from(data) returns 2.5, 3.5, and 5 as they are.
  3. Index and array arguments. For each element the callback computes v * i + arr.length: 5 * 0 + 3, 7 * 1 + 3, and 10 * 2 + 3.

Browser & Runtime Support

TypedArray.prototype.map() is part of ES2015 (ES6), together with the other array-like methods of typed arrays.

✓ Baseline · ES2015

TypedArray.prototype.map()

Supported in every modern browser, plus Node.js, Deno, and Bun.

98% Modern browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer IE 10 and 11 have typed arrays, but not this method
Not supported
map() Excellent

Bottom line: Safe everywhere modern JavaScript runs. Internet Explorer 10 and 11 have typed arrays but not this method, so there you would fill a new typed array in a plain for loop.

Frequently Asked Questions

A new typed array of the same type and the same length as the original. Each element is the result of the callback, converted to the element type.
The results are stored in bytes, so they wrap around at 256. For example 300 becomes 44. Map over Array.from(ta) if you need the exact numbers.
No. The result must fit the element type, so a string such as "7" is turned into the number 7 and "abc" becomes NaN, which an integer array stores as 0.
Array map() can return any type and always builds a plain Array. Typed array map() always builds a typed array of the same type and converts every result.
No. It creates a new typed array with its own buffer. To change elements in place, use forEach() with the array argument, or fill().

Next: reduce()

Combine all elements into one value, such as a sum, a minimum, or a maximum.

reduce() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful