Standard built-ins

ArrayBuffer.prototype.transferToFixedLength()

Try the free JavaScript compiler

Transfers contents to a fixed-length buffer and detaches the original, even when the source was resizable.

Formal Syntax & Structure

javascript syntaxjavascript
buffer.transferToFixedLength(newLength?)

Parameters & Attributes

NameTypeDescription
newLengthnumberTarget size in bytes; defaults to current byte length.

Return Value

ArrayBuffer

New buffer; original is detached on success.

Working Example

Example Snippetjavascript
const b = new ArrayBuffer(2,{maxByteLength:8}); const c=b.transferToFixedLength(4); console.log(b.detached,c.resizable,c.byteLength);
JavaScript Reference