Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. JavaScript
  3. JavaScript リファレンス
  4. 標準組み込みオブジェクト
  5. TypedArray
  6. TypedArray.prototype.slice()

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

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 からendend は含まれない)まで選択された新しい型付き配列オブジェクトにコピーして返します。元の型付き配列は変更されません。このメソッドはArray.prototype.slice() と同じアルゴリズムです。

試してみましょう

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)

引数

start省略可

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

end省略可

抽出を終了する位置を示すゼロ基点のインデックスで、整数に変換されますslice() はここまでを抽出しますが、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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp