subarray()

A typed array method that returns a new view onto part of the same memory, without copying any bytes.

In more detail

Changing the view changes the original, and holding the view keeps the whole original alive. Use slice() when you need an independent copy.

Example

Node.js Buffer.subarray() works the same way; Buffer's older slice() also shares memory and is deprecated, so use buf.copy() for a real copy.

Related terms

Taught in

References