TypedArray.prototype.slice() - JavaScript | MDN

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年9月.

slice()TypedArray インスタンスのメソッドで、型付き配列の一部を start から endend は含まれない)まで選択された新しい型付き配列オブジェクトにコピーして返します。元の型付き配列は変更されません。このメソッドは Array.prototype.slice() と同じアルゴリズムです。

試してみましょう

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

console.log(byteSlice);
// 予想される結果: Uint8Array [20, 30]

構文

js

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

引数

start 省略可

抽出を始める位置を示すゼロ基点のインデックスで、整数に変換されます

end 省略可

抽出を終了する位置を示すゼロ基点のインデックスで、整数に変換されますslice() はここまでを抽出しますが、 end は含みません。

返値

抽出された要素が入った新しい型付き配列です。

解説

詳細については、 Array.prototype.slice() をご覧ください。このメソッドは汎用的ではなく、型付き配列インスタンスに対してのみ呼び出すことができます。

例: 既存の配列の一部を返す

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 ]

仕様書

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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.