Buffer

Buffer.subarray()

Creates a shared view of the selected bytes, with an exclusive end index. Negative indices count from the end. Use Buffer.from(view) when an independent copy is required.

Formal Syntax & Structure

nodejs syntaxnodejs
buf.subarray([start[, end]])

Parameters & Attributes

NameTypeDescription
startintegerStart index, default 0.
endintegerExclusive end, default buffer length.

Return Value

Buffer

View sharing the source storage.

Working Example

Example Snippetnodejs
import { Buffer } from "node:buffer";const bytes = Buffer.from([1, 2, 3]);console.log([...bytes.subarray(1)]);
Node.js Reference