ArrayBuffer

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 DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.

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 .

构造函数

ArrayBuffer()
创建新的 ArrayBuffer 对象。

静态特性

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

静态方法

ArrayBuffer.isView( arg )
返回 true if arg is one of the ArrayBuffer views, such as typed array objects DataView 。返回 false 否则。

实例特性

ArrayBuffer.prototype.byteLength
The read-only size, in bytes, of the ArrayBuffer . This is established when the array is constructed and cannot be changed.

实例方法

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.

范例

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);
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'ArrayBuffer' in that specification.

浏览器兼容性

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

图例

完整支持
完整支持
不支持
不支持
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。

另请参阅

Metadata