ArrayBuffer
Creates a new ArrayBuffer of the given length in bytes, with contents initialized to zero
Syntax
new ArrayBuffer(byteLength)Parameters
| Parameter | Type | Description |
|---|---|---|
| byteLength | number | The size in bytes of the array buffer to create |
Return Value
A new ArrayBuffer object of the specified size
Examples
const buffer = new ArrayBuffer(16)
console.log(buffer.byteLength) // 16const buffer = new ArrayBuffer(8)
const view = new Float64Array(buffer)
view[0] = Math.PI
console.log(new Uint8Array(buffer))async function readFileAsBuffer(file: File): Promise<ArrayBuffer> {
return file.arrayBuffer()
}Understanding ArrayBuffer
The ArrayBuffer method in JavaScript creates a new ArrayBuffer of the given length in bytes, with contents initialized to zero. It belongs to the ArrayBuffer object and is one of the most widely used methods for working with arraybuffer values in modern JavaScript and TypeScript applications.
The method signature is new ArrayBuffer(byteLength). It accepts 1 parameter: byteLength. When called, it returns a new arraybuffer object of the specified size. Understanding when and how to use ArrayBuffer() helps you write more expressive, readable code.
Common use cases for ArrayBuffer include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like arraybuffer-slice, dataview-constructor, uint8array-constructor, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for ArrayBuffer is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
ArrayBuffer.prototype.sliceReturns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from begin up to but not including end
DataViewCreates a new DataView providing a low-level interface for reading and writing multiple number types in an ArrayBuffer
Uint8ArrayCreates a new Uint8Array typed array representing an array of 8-bit unsigned integers initialized to zero
More ArrayBuffer Methods
Other methods in the ArrayBuffer object
Related Tools
More ArrayBuffer Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.