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 ArrayBuffer object.

Static properties

get ArrayBuffer[@@species]
The constructor function that is used to create derived objects.

Static methods

ArrayBuffer.isView(arg)
Returns true if arg is one of the ArrayBuffer views, such as typed array objects or a DataView. Returns false otherwise.

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 ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from begin (inclusive) up to end (exclusive). If either begin or end is 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 (ECMA-262)
The definition of 'ArrayBuffer' in that specification.

Browser compatibility

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
ArrayBufferChrome Full support 7Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 11.6Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.10
ArrayBuffer() constructorChrome Full support 7Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 11.6Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.10
byteLengthChrome Full support 7Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 11.6Safari Full support 5.1WebView Android Full support 4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 4.2Samsung Internet Android Full support 1.0nodejs Full support 0.10
isViewChrome Full support 32Edge Full support 12Firefox Full support 29IE Full support 11Opera Full support 19Safari Full support 7WebView Android Full support ≤37Chrome Android Full support 32Firefox Android Full support 29Opera Android Full support 19Safari iOS Full support 7Samsung Internet Android Full support 2.0nodejs Full support 4.0.0
sliceChrome Full support 17Edge Full support 12Firefox Full support 12
Notes
Full support 12
Notes
Notes The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
IE Full support 11Opera Full support 12.1Safari Full support 6WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 14
Notes
Full support 14
Notes
Notes The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
Opera Android Full support 12.1Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support 0.12
@@speciesChrome Full support 51Edge Full support 13Firefox Full support 48IE No support NoOpera Full support 38Safari Full support 10WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support 48Opera Android Full support 41Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.5.0
Full support 6.5.0
Full support 6.0.0
Disabled
Disabled From version 6.0.0: this feature is behind the --harmony runtime flag.

Legend

Full support
Full support
No support
No support
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also