[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer [Back]  [Original]

ArrayBuffer - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

ArrayBuffer

Baseline Widely available *

This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.

* Some parts of this feature may have varying levels of support.

ArrayBuffer ArrayBuffer DataView TypedArray ArrayBuffer

In this article

js
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 ArrayBuffer constructor's length property whose value is 1.

ArrayBuffer[Symbol.species]

The constructor function that is used to create derived objects.

ArrayBuffer

Allows the addition of properties to all ArrayBuffer objects.

ArrayBuffer.isView(arg)

Returns true if arg is one of the ArrayBuffer views, such as typed array objects or a DataView. Returns false otherwise.

ArrayBuffer.transfer(oldBuffer [, newByteLength])

Returns a new ArrayBuffer whose contents are taken from the oldBuffer's data and then is either truncated or zero-extended by newByteLength.

ArrayBuffer

ArrayBuffer ArrayBuffer.

ArrayBuffer.prototype[Symbol.toStringTag]

The initial value of the Symbol.toStringTag property is the string "ArrayBuffer". This property is used in Object.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 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.

In this example, we create a 8-byte buffer with a Int32Array view referring to the buffer:

js
var buffer = new ArrayBuffer(8);
var view = new Int32Array(buffer);

Specification
ECMAScript 2027 LanguageSpecification
# 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.

js
var dv = ArrayBuffer(10);
// TypeError: calling a builtin ArrayBuffer constructor
// without new is forbidden
js
var dv = new ArrayBuffer(10);


Web Proxy Viewer  |  New URL  |  Original Page