Standard built-ins
ArrayBuffer.prototype.transferToFixedLength()
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
| 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,{maxByteLength:8}); const c=b.transferToFixedLength(4); console.log(b.detached,c.resizable,c.byteLength);