ArrayBuffer
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015å¹´7æâ©.
* Some parts of this feature may have varying levels of support.
ArrayBuffer ç©ä»¶æ¯ä¸ç¨®è¡¨ç¤ºéç¨ãåºå®å¤§å°çåå§äºé²å¶è³æç·©è¡ãæ³è¦ç´æ¥æä½ä¸å ArrayBuffer ç©ä»¶çå
§å®¹æ¯ä¸å¯è½çãè¥è¦è®å¯«è©²ç·©è¡çå
§å®¹åå¿
é ééè¦åï¼å¯ä»¥é¸æå»ºç«ä¸å DataView è¦åç©ä»¶ææ¯ä¸åéå®å
¶æå¡çºæç¨®åå¥ç TypedArray è¦åç©ä»¶ï¼å®åçè½ä»¥ç¹å®çåå¥è§£è®ãä¿®æ¹ ArrayBufferã
èªæ³
new ArrayBuffer(length)
忏
length-
è¦å»ºç«çç·©è¡é£å大å°ï¼ä»¥ä½å çµï¼byteï¼è¨ç®ã
åå³å¼
çºä¸åæ°å»ºç«çæå®å¤§å° ArrayBuffer ç©ä»¶ï¼å
¶å
§å®¹çåå§åçº 0ã
Exceptions
A RangeError is thrown if the length is larger than Number.MAX_SAFE_INTEGER (>= 2 ** 53) or negative.
說æ
The ArrayBuffer constructor creates a new ArrayBuffer of the given length in bytes.
徿¢æçè³æåå¾ ArrayBuffer
屬æ§
ArrayBuffer.length-
The
ArrayBufferconstructor's length property whose value is 1. ArrayBuffer[Symbol.species]-
The constructor function that is used to create derived objects.
ArrayBuffer.prototype-
Allows the addition of properties to all
ArrayBufferobjects.
æ¹æ³
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.
ArrayBuffer 實ä¾
ææç ArrayBuffer ç©ä»¶å¯¦ä¾çç¹¼æ¿èª ArrayBuffer.prototype.
屬æ§
ArrayBuffer.prototype[Symbol.toStringTag]-
The initial value of the
Symbol.toStringTagproperty is the string"ArrayBuffer". This property is used inObject.prototype.toString(). 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()-
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.
ç¯ä¾
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 |
|---|
| ECMAScript® 2026 Language Specification > # sec-arraybuffer-objects > |
ç覽å¨ç¸å®¹æ§
ç¸å®¹æ§å註
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);