TypedArray.prototype.slice() - JavaScript | MDN

Try it

const bytes = new Uint8Array([10, 20, 30, 40, 50]);
const byteSlice = bytes.slice(1, 3);

console.log(byteSlice);
// Expected output: Uint8Array [20, 30]

Syntax

js

slice()
slice(start)
slice(start, end)

Parameters

start Optional

Zero-based index at which to start extraction, converted to an integer.

end Optional

Zero-based index at which to end extraction, converted to an integer. slice() extracts up to but not including end.

Return value

A new typed array containing the extracted elements.

Description

See Array.prototype.slice() for more details. This method is not generic and can only be called on typed array instances.

Examples

Return a portion of an existing typed array

js

const bytes = new Uint8Array([1, 2, 3]);
bytes.slice(1); // Uint8Array [ 2, 3 ]
bytes.slice(2); // Uint8Array [ 3 ]
bytes.slice(-2); // Uint8Array [ 2, 3 ]
bytes.slice(0, 1); // Uint8Array [ 1 ]

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-%typedarray%.prototype.slice

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.