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 new
ArrayBufferobjects.
Properties
ArrayBuffer.length- The
ArrayBufferconstructor's length property whose value is 1. get ArrayBuffer[@@species]- The constructor function that is used to create derived objects.
ArrayBuffer.prototype- Allows the addition of properties to all
ArrayBufferobjects.
Methods
ArrayBuffer.isView(arg)- Returns
trueifargis one of the ArrayBuffer views, such as typed array objects or aDataView. Returnsfalseotherwise. ArrayBuffer.transfer(oldBuffer [, newByteLength])-
Returns a new
ArrayBufferwhose contents are taken from theoldBuffer's data and then is either truncated or zero-extended bynewByteLength.
Instances
All ArrayBuffer instances inherit from ArrayBuffer.prototype.
Properties
- ArrayBuffer.prototype.constructor
- Specifies the function that creates an object's prototype. The initial value is the standard built-in
ArrayBufferconstructor. ArrayBuffer.prototype.byteLengthRead only- The size, in bytes, of the array. This is established when the array is constructed and cannot be changed. Read only.
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.
Example
In this example, we create a 8-byte buffer with a Int32Array view referring to the buffer:
var buffer = new ArrayBuffer(8); var view = new Int32Array(buffer);
Specifications
| Specification |
|---|
| ECMAScript Latest Draft (ECMA-262) The definition of 'ArrayBuffer' in that specification. |
Browser compatibility
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ArrayBuffer | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support 4 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
byteLength | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support 4 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
isView | Chrome Full support 32 | Edge Full support 12 | Firefox Full support 29 | IE Full support 11 | Opera Full support Yes | Safari Full support 7 | WebView Android Full support ≤37 | Chrome Android Full support 32 | Firefox Android Full support 29 | Opera Android Full support Yes | Safari iOS Full support 7 | Samsung Internet Android Full support 2.0 | nodejs Full support Yes |
ArrayBuffer() without new throws | Chrome Full support 7 | Edge Full support 14 | Firefox Full support 44 | IE No support No | Opera Full support Yes | Safari Full support 5.1 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support 44 | Opera Android Full support Yes | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 | nodejs Full support 0.12 |
prototype | Chrome Full support 7 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 11.6 | Safari Full support 5.1 | WebView Android Full support 4 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 12 | Safari iOS Full support 4.2 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
slice | Chrome Full support 17 | Edge Full support 12 | Firefox
Full support
12
| IE Full support 11 | Opera Full support Yes | Safari Full support 6 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android
Full support
14
| Opera Android Full support Yes | Safari iOS Full support 6 | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
transfer | Chrome No support No | Edge No support No | Firefox No support No | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
@@species | Chrome Full support 51 | Edge Full support 13 | Firefox Full support 48 | IE No support No | Opera Full support 38 | Safari Full support 10 | WebView Android Full support 51 | Chrome Android Full support 51 | Firefox Android Full support 48 | Opera Android Full support 41 | Safari iOS Full support 10 | Samsung Internet Android Full support 5.0 | nodejs
Full support
6.5.0
|
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.