Standard built-ins
ArrayBuffer.prototype.transfer()
Creates a new buffer with copied or moved contents, detaches the original, and preserves resizability when applicable. Extension is zero-filled.
Formal Syntax & Structure
javascript syntaxjavascript
buffer.transfer(newLength?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| newLength | number | Target 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); new Uint8Array(b).set([7,8]); const c = b.transfer(3); console.log(b.detached, JSON.stringify([...new Uint8Array(c)]));