The ArrayBuffer
object is used to represent a generic, fixed-length raw binary data buffer. 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.
new ArrayBuffer(length)
length
A new ArrayBuffer
object of the specified size. Its contents are initialized to 0.
The ArrayBuffer
constructor creates a new ArrayBuffer
of the given length in bytes.
ArrayBuffer.length
ArrayBuffer
constructor's length property whose value is 1.get ArrayBuffer[@@species]
ArrayBuffer.prototype
ArrayBuffer
objects.ArrayBuffer.isView(arg)
true
if arg
is one of the ArrayBuffer views, such as typed array objects or a DataView
. Returns false
otherwise.ArrayBuffer.transfer(oldBuffer [, newByteLength])
ArrayBuffer
whose contents are taken from the oldBuffer
's data and then is either truncated or zero-extended by newByteLength
.ArrayBuffer
instancesAll ArrayBuffer
instances inherit from ArrayBuffer.prototype
.
ArrayBuffer
constructor.ArrayBuffer.prototype.byteLength
Read only
ArrayBuffer.prototype.slice()
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.ArrayBuffer.slice()
ArrayBuffer.prototype.slice()
.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);
Specification | Status | Comment |
---|---|---|
Typed Array Specification | Obsolete | Superseded by ECMAScript 6. |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'ArrayBuffer' in that specification. | Standard | Initial definition in an ECMA standard. Specified that new is required. |
ECMAScript 2017 Draft (ECMA-262) The definition of 'ArrayBuffer' in that specification. | Draft |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 7.0 | 4.0 (2) | 10 | 11.6 | 5.1 |
ArrayBuffer() without new throws | ? | 44 (44) | ? | ? | ? |
ArrayBuffer.slice()
| No support |
(Yes) No support 53 (53) | No support | No support | ? |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 4.0 | (Yes) | 4.0 (2) | 10 | 11.6 | 4.2 |
ArrayBuffer() without new throws | ? | ? | 44.0 (44) | ? | ? | ? |
ArrayBuffer.slice()
| No support | No support |
(Yes) No support 53.0 (53) | No support | No support | ? |
Starting with ECMAScript 2015, ArrayBuffer
constructors require to be constructed with a new
operator. Calling an ArrayBuffer
constructor as a function without new
, will throw a TypeError
from now on.
var dv = ArrayBuffer(10); // TypeError: calling a builtin ArrayBuffer constructor // without new is forbidden
var dv = new ArrayBuffer(10);
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer