ArrayBuffer
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer.
It is an array of bytes, often referred to in other languages as a "byte array". You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.
The ArrayBuffer() constructor creates a new ArrayBuffer of the given length in bytes. You can also get an array buffer from existing data, for example, from a Base64 string or from a local file.
Constructor
ArrayBuffer()-
Creates a new
ArrayBufferobject.
Static properties
get ArrayBuffer[@@species]-
The constructor function that is used to create derived objects.
Static methods
ArrayBuffer.isView(arg)-
Returns
trueifargis one of the ArrayBuffer views, such as typed array objects or aDataView. Returnsfalseotherwise.
Instance properties
ArrayBuffer.prototype.byteLength-
The read-only size, in bytes, of the
ArrayBuffer. This is established when the array is constructed and cannot be changed.
Instance methods
ArrayBuffer.prototype.slice()-
Returns a new
ArrayBufferwhose contents are a copy of thisArrayBuffer's bytes frombegin(inclusive) up toend(exclusive). If eitherbeginorendis negative, it refers to an index from the end of the array, as opposed to from the beginning.
Examples
Creating an ArrayBuffer
In this example, we create a 8-byte buffer with a Int32Array view referring to the buffer:
const buffer = new ArrayBuffer(8);
const view = new Int32Array(buffer);
Specifications
| Specification |
|---|
| ECMAScript Language Specification # sec-arraybuffer-objects |
Browser compatibility
BCD tables only load in the browser