Skip to main content

ArrayBuffer.prototype.transfer and friends

Less than 1 minutefeaturees-proposal

ArrayBuffer.prototype.transfer and friendsopen in new window

Note

ArrayBuffer.prototype.{ transfer, transferToFixedLength } polyfilled only in runtime with native structuredClone with ArrayBuffer transfer support.

Modules

Types

interface ArrayBuffer {
  get detached(): boolean;
  transfer(newLength?: number): ArrayBuffer;
  transferToFixedLength(newLength?: number): ArrayBuffer;
}

Entry points

core-js/proposals/array-buffer-transfer
core-js/actual|full/array-buffer
core-js/actual|full/array-buffer/detached
core-js/actual|full/array-buffer/transfer
core-js/actual|full/array-buffer/transfer-to-fixed-length

Example

Exampleopen in new window:

const buffer = Int8Array.of(1, 2, 3, 4, 5, 6, 7, 8).buffer;
console.log(buffer.byteLength); // => 8
console.log(buffer.detached); // => false
const newBuffer = buffer.transfer(4);
console.log(buffer.byteLength); // => 0
console.log(buffer.detached); // => true
console.log(newBuffer.byteLength); // => 4
console.log(newBuffer.detached); // => false
console.log([...new Int8Array(newBuffer)]); // => [1, 2, 3, 4]