Skip to content

ArrayBuffer

In one line

An ArrayBuffer is a fixed-length chunk of raw binary memory, accessed through typed array views.

In simple words

An ArrayBuffer represents a fixed-length, contiguous block of raw bytes in memory. You cannot read or write it directly — you create a typed array view (Int8Array, Uint16Array, Float32Array, etc.) or a DataView over it, which interprets the bytes as numbers of a specific type.

ArrayBuffer is the foundation for efficient binary data handling in JavaScript: file I/O (Blob/File), WebSockets binary frames, WebAssembly linear memory, Canvas pixel data, and the Structured Clone algorithm. It lets you process binary data without copying it into JS numbers.

To create one: new ArrayBuffer(byteLength). To view it: new Uint8Array(buffer). Typed arrays share the underlying buffer — multiple views can interpret the same bytes differently. transfer() detaches a buffer (makes it unusable) to move ownership, e.g. to a worker.

Example

javascript
const buf = new ArrayBuffer(8); // 8 bytes
const view = new Uint8Array(buf); // view as bytes

view[0] = 255;
view[1] = 128;
console.log(view[0], view[1]); // 255 128
console.log(buf.byteLength); // 8

// A different view over the same buffer
const asInt32 = new Int32Array(buf);
console.log(asInt32.length); // 2 (8 bytes / 4)

The ArrayBuffer holds 8 raw bytes. A Uint8Array views them as bytes; an Int32Array views the same bytes as 2 integers.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary