Movatterモバイル変換


[0]ホーム

URL:


  1. Tecnologia Web para desenvolvedores
  2. JavaScript
  3. Referência JavaScript
  4. Objetos Globais
  5. ArrayBuffer

Esta página foi traduzida do inglês pela comunidade.Saiba mais e junte-se à comunidade MDN Web Docs.

View in EnglishAlways switch to English

ArrayBuffer

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨julho de 2015⁩.

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

O objetoArrayBuffer é um tipo de dado usado para representar um genérico, buffer de dados binários de tamanho fixo. Você não pode manipular diretamente os conteúdos de umArrayBuffer; em vez disso, você cria um objetoArrayBufferView que representa o buffer em um formato específico, e usa para ler e escrever os conteúdos do buffer.

Experimente

// Create an ArrayBuffer with a size in bytesconst buffer = new ArrayBuffer(8);console.log(buffer.byteLength);// Expected output: 8

Syntax

new ArrayBuffer(length)

Parameters

length

The size, in bytes, of the array buffer to create.

Return value

A newArrayBuffer object of the specified size. Its contents are initialized to 0.

Exceptions

ARangeError is thrown if thelength is larger thanNumber.MAX_SAFE_INTEGER (>= 2 ** 53) or negative.

Description

TheArrayBuffer constructor creates a newArrayBuffer of the given length in bytes.

Getting an array buffer from existing data

Properties

ArrayBuffer.length

TheArrayBuffer constructor'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 allArrayBuffer objects.

Methods

ArrayBuffer.isView(arg)

Returnstrue ifarg is one of the ArrayBuffer views, such astyped array objects or aDataView. Returnsfalse otherwise.

ArrayBuffer.transfer(oldBuffer [, newByteLength])Experimental

Returns a newArrayBuffer whose contents are taken from theoldBuffer's data and then is either truncated or zero-extended bynewByteLength.

Instances

AllArrayBuffer instances inherit fromArrayBuffer.prototype.

Properties

Methods

ArrayBuffer.slice()Não padrão

Has the same functionality asArrayBuffer.prototype.slice().

Exemplo

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

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

Especificações

Specification
ECMAScript® 2026 Language Specification
# sec-arraybuffer-objects

Compatibilidade com navegadores

Compatibility notes

Starting with ECMAScript 2015,ArrayBuffer constructors require to be constructed with anew operator. Calling anArrayBuffer constructor as a function withoutnew, will throw aTypeError from now on.

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

Veja também

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp