typed arrays
Typed arrays are array-like objects that hold numbers of one fixed binary type, such as 8-bit unsigned integers or 64-bit floats, packed into a block of raw memory. Each one is a view over an ArrayBuffer, and each value written is converted to the view’s element type, so an out-of-range integer wraps around:
> const levels = new Uint8Array([10, 200, 255]);
undefined
> levels[1] = 300;
300
> levels
Uint8Array(3) [ 10, 44, 255 ]
> Array.isArray(levels)
false
JavaScript has twelve typed array constructors, such as Uint8Array, Int16Array, and Float64Array. They share a hidden superclass that the specification calls TypedArray, which holds the common methods but has no global name. Typed arrays have been part of the language since ES2015 and are Baseline Widely available.
Float16Array and Math.f16round() were added in ES2025 and are Baseline Newly available since 2025. The Uint8Array base64 and hex methods were added in ES2026 and are Baseline Newly available since 2025.
Syntax
Every concrete typed array constructor accepts the same forms:
new <TypedArray>()
new <TypedArray>(<length>)
new <TypedArray>(<source>)
new <TypedArray>(<buffer>[, <byteOffset>[, <length>]])
| Parameter | Description |
|---|---|
TypedArray |
One of the twelve constructors listed in the table below |
length |
The number of elements. Without a buffer, a new buffer is allocated and every element starts at zero. With a buffer, it’s how many elements the view covers |
source |
Another typed array, an array, or any iterable or array-like object whose values are converted and copied in |
buffer |
An ArrayBuffer or SharedArrayBuffer to view without copying |
byteOffset |
Optional. The byte where the view starts, which must be a multiple of the element size. Defaults to 0 |
The new keyword is required, and calling a constructor without it throws a TypeError. A view created over a resizable buffer without a length tracks the buffer’s size as it grows or shrinks.
The twelve constructors differ only in the element type they store:
| Constructor | Bytes per element | Values |
|---|---|---|
Int8Array, Uint8Array |
1 | Signed or unsigned 8-bit integers |
Uint8ClampedArray |
1 | Unsigned 8-bit integers that clamp to 0 to 255 instead of wrapping |
Int16Array, Uint16Array |
2 | Signed or unsigned 16-bit integers |
Int32Array, Uint32Array |
4 | Signed or unsigned 32-bit integers |
Float16Array |
2 | 16-bit floats (ES2025) |
Float32Array, Float64Array |
4, 8 | 32-bit or 64-bit IEEE 754 floats |
BigInt64Array, BigUint64Array |
8 | Signed or unsigned 64-bit integers, read and written as bigint values |
Type a number below to see how each constructor that stores plain numbers converts it, and which bytes it writes into memory:
Key Static Methods and Properties
| Member | Kind | Description |
|---|---|---|
TypedArray.from() |
Static method | Creates a typed array from an iterable or array-like object, with an optional mapping function |
TypedArray.of() |
Static method | Creates a typed array from its arguments |
TypedArray.BYTES_PER_ELEMENT |
Static and instance property | Returns the size of one element in bytes, such as 2 for Int16Array |
Uint8Array.fromBase64(), Uint8Array.fromHex() |
Static method | Create a Uint8Array by decoding a base64 or hex string (ES2026) |
Math.f16round() |
Static method | Returns the nearest 16-bit float to a number, matching what a Float16Array stores (ES2025) |
Key Instance Methods and Properties
| Member | Kind | Description |
|---|---|---|
.length |
Instance property | Returns the number of elements, which can’t be changed by assignment |
.buffer, .byteOffset, .byteLength |
Instance property | Return the underlying buffer, where the view starts in it, and how many bytes it covers |
.set() |
Instance method | Copies values from an array or typed array into this one, starting at an optional index |
.subarray() |
Instance method | Returns a new view over part of the same buffer, without copying |
.slice() |
Instance method | Returns a copy of part of the array in a new buffer |
.fill() |
Instance method | Sets a range of elements to one value, in place |
.map(), .filter(), .reduce() |
Instance method | Work like the Array methods, but .map() and .filter() return a typed array of the same type |
.sort(), .toSorted() |
Instance method | Sort numerically in place, or return a sorted copy (.toSorted() is ES2023) |
.at() |
Instance method | Returns the element at an index, counting from the end for negative indexes (ES2022) |
.toBase64(), .toHex() |
Instance method | Return the bytes of a Uint8Array as a base64 or hex string (ES2026) |
.setFromBase64(), .setFromHex() |
Instance method | Decode a base64 or hex string into an existing Uint8Array and report the characters read and bytes written (ES2026) |
Typed arrays also have most other Array methods, such as .forEach(), .indexOf(), .includes(), and .with(). Methods that change length, such as .push() and .splice(), don’t exist because a typed array’s size is fixed.
Examples
An audio tool stores a short clip as 16-bit samples. The constructor allocates a zeroed buffer of the right size, and .byteLength reports the memory it uses:
> const samples = new Int16Array(4);
undefined
> samples.BYTES_PER_ELEMENT
2
> samples.byteLength
8
A network protocol splits a packet into a two-byte header and a payload. The .subarray() method returns a view over the same bytes, so a write through it changes the packet, while .slice() returns an independent copy:
> const packet = new Uint8Array([1, 2, 3, 4, 5, 6]);
undefined
> const header = packet.subarray(0, 2);
undefined
> const copy = packet.slice(0, 2);
undefined
> header[0] = 99;
99
> copy[1] = 0;
0
> packet
Uint8Array(6) [ 99, 2, 3, 4, 5, 6 ]
An API returns a signature as base64 text, and a log line needs it in hex. The Uint8Array methods convert between the two without any helper library:
> const signature = Uint8Array.fromBase64("SGkh");
undefined
> signature
Uint8Array(3) [ 72, 105, 33 ]
> signature.toHex()
'486921'
> signature.toBase64()
'SGkh'
An image filter brightens pixel values and must keep them in the 0 to 255 range. A Uint8ClampedArray clamps and rounds each value, while a Uint8Array wraps it around:
> new Uint8ClampedArray([300, -20, 127.5])
Uint8ClampedArray(3) [ 255, 0, 128 ]
> new Uint8Array([300, -20, 127.5])
Uint8Array(3) [ 44, 236, 127 ]
Common Gotchas
The .map() method returns a typed array of the same type, so results that don’t fit the element type are converted. Array.from() with a mapping function returns a regular array instead:
> new Uint8Array([200, 100]).map((n) => n * 2)
Uint8Array(2) [ 144, 200 ]
> Array.from(new Uint8Array([200, 100]), (n) => n * 2)
[ 400, 200 ]
Floats are rounded to the element’s precision when stored, so a Float32Array doesn’t give back the exact number it was given:
> new Float32Array([0.1])[0]
0.10000000149011612
> new Float16Array([0.1, 70000])
Float16Array(2) [ 0.0999755859375, Infinity ]
A view over an existing buffer must start at a multiple of its element size, so a misaligned byteOffset throws a RangeError:
> new Float32Array(new ArrayBuffer(8), 2)
Uncaught RangeError: start offset of Float32Array should be a multiple of 4
at new Float32Array (<anonymous>)
Related Resources
Course
Lists With Arrays
Write JavaScript functions that answer questions about a list: build an array, loop over its items, then count, total, select, and find what you need, with a clear answer even when the list is empty.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 12, 2026