Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

TypedArray.prototype.slice()

BaselineWidely available

Theslice() method ofTypedArray instances returns a copy of a portion of a typed array into a new typed array object selected fromstart toend (end not included) wherestart andend represent the index of items in that typed array. The original typed array will not be modified. This method has the same algorithm asArray.prototype.slice().

Try it

const uint8 = new Uint8Array([10, 20, 30, 40, 50]);const array1 = uint8.slice(1, 3);console.log(array1);// Expected output: Uint8Array [20, 30]

Syntax

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

Parameters

startOptional

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

endOptional

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

Return value

A new typed array containing the extracted elements.

Description

SeeArray.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 uint8 = new Uint8Array([1, 2, 3]);uint8.slice(1); // Uint8Array [ 2, 3 ]uint8.slice(2); // Uint8Array [ 3 ]uint8.slice(-2); // Uint8Array [ 2, 3 ]uint8.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 byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp