JavaScript TypedArray

Beginner
8 min read
Updated: Nov 2026
3 examples
Binary data

Definition and Usage

In JavaScript, a typed array is an array-like list of numbers that all have the same numeric type, for example only 8-bit unsigned integers (Uint8Array) or only 32-bit floating-point numbers (Float32Array). You read and write it with indexes, just like a normal array: bytes[0], bytes.length.

Under the hood a typed array is a view over an ArrayBuffer, a block of raw bytes. The buffer stores the bytes; the typed array decides how to read them as numbers. Its length is fixed when you create it, and every new element starts at 0.

You meet typed arrays whenever JavaScript handles binary data: file and network bytes, canvas pixels (ImageData.data is a Uint8ClampedArray), Web Audio samples (Float32Array), and WebGL buffers. This page teaches the ideas; the TypedArray Methods index lists all 34 method guides (TypedArray.from(), subarray(), sort(), and more).

Typed array = one number type + fixed length + shared bytes.

Print a typed array with ta.join(' ') or Array.from(ta).join(', '). Browsers and Node.js format console.log(ta) differently, so the examples on this site always turn it into text first.

JavaScript Syntax

Common ways to create a typed array:

JavaScript
const zeros = new Uint8Array(4);             // 4 elements, all 0
const fromList = new Int16Array([5, -2, 300]);  // copy numbers in
const view = new Float32Array(buffer, 8, 2);  // view 2 floats of an existing buffer
const mapped = Uint8Array.from('123', Number); // TypedArray.from()
const listed = Int32Array.of(7, 8, 9);         // TypedArray.of()

zeros.length;              // 4  (elements)
fromList.byteLength;       // 6  (3 elements x 2 bytes)
Int16Array.BYTES_PER_ELEMENT; // 2

The 11 Typed Array Types

Pick the type by the kind of number you need to store. Each element uses BYTES_PER_ELEMENT bytes.

TypeBytes per elementValue rangeTypical use
Int8Array1-128 to 127Small signed numbers
Uint8Array10 to 255Raw bytes: files, network data
Uint8ClampedArray10 to 255 (clamped)Canvas pixel colors
Int16Array2-32,768 to 32,76716-bit audio samples
Uint16Array20 to 65,535Counts, character codes
Int32Array4about -2.1 billion to 2.1 billionLarge whole numbers
Uint32Array40 to about 4.29 billionIDs, colors as 0xRRGGBBAA
Float32Array4about ±3.4 × 1038, about 7 digitsGraphics (WebGL), Web Audio
Float64Array8same as a normal JavaScript numberPrecise decimal math
BigInt64Array8-263 to 263 - 1 (BigInt)64-bit signed integers
BigUint64Array80 to 264 - 1 (BigInt)64-bit unsigned integers

A twelfth type, Float16Array (half-precision floats), was added in ES2025. It is still new, so this tutorial sticks to the 11 long-standing types.

How Values Are Stored

A typed array never stores a value as you wrote it if that value does not fit the type. It converts it instead, without an error:

  • Integer types wrap around. In a Uint8Array, 256 becomes 0 and -1 becomes 255. Decimals are cut off: 9.9 becomes 9.
  • Uint8ClampedArray clamps. 300 becomes 255 and -5 becomes 0. Decimals are rounded, with halves going to the even number (2.5 becomes 2).
  • Float32Array rounds to single precision. 0.1 is read back as 0.10000000149011612. Use Float64Array for the same precision as normal JavaScript numbers.
  • BigInt types only take BigInts. new BigInt64Array([1]) throws a TypeError; write [1n].

Typed Array vs Normal Array

QuestionNormal ArrayTyped array
What can it hold?Any values, mixed: numbers, strings, objectsOnly numbers of one type (BigInts for the BigInt types)
Can the length change?Yes: push(), pop(), splice()No: the length is fixed when it is created
Empty slots?Can have holesNo holes; new elements start at 0
Where is the data?Managed by the enginePacked bytes in an ArrayBuffer (ta.buffer)
Default sort()Compares as strings: [10, 9, 100] becomes 10, 100, 9Compares as numbers: 9, 10, 100
map() / filter() returnA new ArrayA new typed array of the same type
Wrong value writtenStored as it isConverted: wraps, clamps, or rounds
Array.isArray()truefalse

One exception to the fixed length: a typed array created on a resizable buffer without a length follows the buffer's size (see ArrayBuffer resize()).

The Hidden TypedArray Class

All 11 types inherit their methods from one parent class called TypedArray. It is not a global: typeof TypedArray is "undefined", and you can only reach it with Object.getPrototypeOf(Int8Array). That is why method names on this site are written as TypedArray.from() or TypedArray.prototype.map(), while your code calls Uint8Array.from() or scores.map() on a real type.

Typed arrays are not arrays: Array.isArray(new Uint8Array(2)) is false. When you need array-only methods such as push(), convert first with Array.from(ta) or [...ta].

JavaScript Examples

Three short programs that show what makes typed arrays different.

Example 1 — Create a Typed Array and Inspect It

Make a Uint8Array from a list of numbers, then read its length, its size in bytes, and its elements.

JavaScript
const scores = new Uint8Array([12, 250, 7]);

console.log(scores.length);             // 3
console.log(scores.BYTES_PER_ELEMENT);  // 1
console.log(scores.byteLength);         // 3
console.log(scores.join(' '));          // 12 250 7
console.log(Array.isArray(scores));     // false

How It Works

  1. A fixed-size list of bytes. new Uint8Array([12, 250, 7]) copies three numbers into a fresh three-byte buffer, so length is 3 and cannot grow later.
  2. Elements versus bytes. Each Uint8Array element takes exactly one byte, so byteLength equals length here. In an Int16Array it would be twice as big.
  3. Array-like, not an Array. join() works the same as on a normal array, but Array.isArray() says false: a typed array is its own kind of object.

Example 2 — Values Are Converted to the Type

Put the same out-of-range numbers into three different types and see how each one stores them.

JavaScript
const wrapped = new Uint8Array([256, -1, 300]);
const clamped = new Uint8ClampedArray([256, -1, 300]);
const single = new Float32Array([0.1]);

console.log(String(wrapped));  // 0,255,44
console.log(String(clamped));  // 255,0,255
console.log(single[0]);        // 0.10000000149011612
console.log(single[0] === 0.1);  // false
set() tutorial

How It Works

  1. Uint8Array wraps around. Only 0 to 255 fits in one byte, so 256 turns into 0, -1 into 255, and 300 into 44 (300 minus 256).
  2. Uint8ClampedArray stops at the edges. The clamped type pins anything above 255 to 255 and anything below 0 to 0, which is exactly what pixel colors need.
  3. Float32Array loses precision. A 32-bit float cannot hold 0.1 exactly. Reading it back gives the nearest single-precision value, so the comparison with 0.1 is false.

Example 3 — Two Typed Arrays on One Buffer

A typed array can cover only part of an ArrayBuffer. Two views on the same bytes see each other's changes.

JavaScript
const buffer = new ArrayBuffer(4);
const all = new Uint8Array(buffer);
const lastTwo = new Uint8Array(buffer, 2, 2);

lastTwo[0] = 7;
all[3] = 9;

console.log(all.join(' '));                  // 0 0 7 9
console.log(lastTwo.join(' '));              // 7 9
console.log(lastTwo.byteOffset);             // 2
console.log(all.buffer === lastTwo.buffer);  // true

How It Works

  1. One buffer, two windows. all sees all four bytes. lastTwo starts at byte 2 and is 2 elements long, so its index 0 is byte 2 of the buffer.
  2. Writes go to the shared bytes. Setting lastTwo[0] fills byte 2 and setting all[3] fills byte 3. Nothing is copied, so both views show both changes.
  3. Offset and buffer tell the story. byteOffset is 2 for the smaller view, and both .buffer properties point to the very same ArrayBuffer.

TypedArray Method Groups

Typed arrays have 34 methods in this tutorial. Each one has a full guide with examples you can run in the browser.

GroupMethodsUse them to
Create typed arraysTypedArray.from() TypedArray.of()Static methods on a concrete constructor such as Uint8Array or Int16Array. They build a brand-new typed array.
Read and findat() find() findIndex() findLast() findLastIndex() includes() indexOf() lastIndexOf()Read one element, or search for a value or for the first or last element that passes a test.
Loop, test, and transformevery() some() forEach() filter() map() reduce() reduceRight()Run a callback for each element. The callback gets (value, index, array). map() and filter() return a new typed array of the same type.
Copy, fill, and viewsset() subarray() slice() fill() copyWithin()Copy values in, copy a part out, make a view that shares memory, or overwrite a range with one value.
Reorder in placereverse() sort()Change the order of the elements inside the same typed array. sort() is numeric by default.
Make a changed copy (ES2023)toReversed() toSorted() with()Non-mutating versions that return a new typed array and leave the original exactly as it was.
Join and convert to textjoin() toString() toLocaleString()Turn the numbers into one string, with a separator or with locale formatting.
Iteratekeys() values() entries() [Symbol.iterator]()Get an iterator of indexes, values, or [index, value] pairs for for...of loops, spread, and Array.from().

Full list with descriptions, constructors, and properties: TypedArray Methods index.

Frequently Asked Questions

A typed array is an array-like list of numbers that all share one numeric type, such as Uint8Array for bytes or Float32Array for 32-bit floats. It has a fixed length and stores its numbers as raw bytes in an ArrayBuffer.
Not directly. TypedArray is the hidden parent class of the 11 types and is not a global, so typeof TypedArray is "undefined". You always use a real type: new Uint8Array(4), Uint8Array.from(list), or Int16Array.of(1, 2).
Its length is fixed when you create it, so push(), pop(), splice(), and concat() do not exist. Create a new, bigger typed array and copy the old values in with set(), or convert to a normal array with Array.from().
Uint8Array for raw bytes from files or the network, Uint8ClampedArray for canvas pixels, Int16Array or Float32Array for audio samples, Float32Array for WebGL, Float64Array for precise decimals, and BigInt64Array for 64-bit integers.
An ArrayBuffer only holds raw bytes and has no indexes. A typed array is a view that reads those bytes as numbers. new Uint8Array(4) creates both at once: a 4-byte buffer (ta.buffer) and a view on it.

Browse every TypedArray method

Open the index for from(), at(), map(), sort(), subarray(), toSorted(), and the rest.

TypedArray Methods index →

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.

16 people found this page helpful