W3cubDocs

/JavaScript

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

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
ArrayBuffer 7 12 4 10 11.6 5.1
ArrayBuffer() constructor 7 12 4 10 11.6 5.1
byteLength 7 12 4 10 11.6 5.1
isView 32 12 29 11 19 7
slice 17 12 12
12
The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
11 12.1 6
@@species 51 13 48 No 38 10
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ArrayBuffer 4 18 4 12 4.2 1.0
ArrayBuffer() constructor 4 18 4 12 4.2 1.0
byteLength 4 18 4 12 4.2 1.0
isView ≤37 32 29 19 7 2.0
slice ≤37 18 14
14
The non-standard ArrayBuffer.slice() method has been removed in Firefox 53 (but the standardized version ArrayBuffer.prototype.slice() is kept.
12.1 6 1.0
@@species 51 51 48 41 10 5.0
Server
Node.js
ArrayBuffer 0.10
ArrayBuffer() constructor 0.10
byteLength 0.10
isView 4.0.0
slice 0.12
@@species 6.5.0
6.5.0
6.0.0
Disabled
Disabled From version 6.0.0: this feature is behind the --harmony runtime flag.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer