このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
TypedArray.prototype.slice()
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 からend (end は含まれない)まで選択された新しい型付き配列オブジェクトにコピーして返します。元の型付き配列は変更されません。このメソッドはArray.prototype.slice() と同じアルゴリズムです。
In this article
試してみましょう
const uint8 = new Uint8Array([10, 20, 30, 40, 50]);const array1 = uint8.slice(1, 3);console.log(array1);// Expected output: Uint8Array [20, 30]構文
js
slice()slice(start)slice(start, end)引数
返値
抽出された要素が入った新しい型付き配列です。
解説
詳細については、Array.prototype.slice() をご覧ください。このメソッドは汎用的ではなく、型付き配列インスタンスに対してのみ呼び出すことができます。
例
>例: 既存の配列の一部を返す
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 ]仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-%typedarray%.prototype.slice> |