Standard built-ins

ArrayBuffer.prototype.resize()

Try the free JavaScript compiler

Resizes a resizable ArrayBuffer within maxByteLength; throws for invalid sizes or fixed buffers.

Formal Syntax & Structure

javascript syntaxjavascript
buffer.resize(newByteLength)

Parameters & Attributes

NameTypeDescription
newByteLengthnumberNew byte length within maximum.

Return Value

undefined

Resizes a resizable ArrayBuffer within maxByteLength; throws for invalid sizes or fixed buffers.

Working Example

Example Snippetjavascript
(async () => {const b=new ArrayBuffer(2,{maxByteLength:4});b.resize(4);console.log(b.byteLength,b.resizable,JSON.stringify([...new Uint8Array(b)]));})()
JavaScript Reference