Movatterモバイル変換


[0]ホーム

URL:


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

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

View in EnglishAlways switch to English

TypedArray.prototype.length

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

lengthTypedArray インスタンスのアクセサープロパティで、型付き配列の長さを(要素数で)返します。

試してみましょう

// Create an ArrayBuffer with a size in bytesconst buffer = new ArrayBuffer(8);const uint8 = new Uint8Array(buffer, 2);console.log(uint8.length);// Expected output: 6

解説

length プロパティは set アクセサープロパティがundefined であるアクセサープロパティです。これは、このプロパティが読み取り専用であることを意味します。値はTypedArray が構築されたときに確立し、変更することができません。TypedArraybyteOffset またはlength が指定されていない場合、参照されるArrayBuffer の長さが返されます。TypedArray型付き配列オブジェクトのうちの一つです。

length プロパティの使用

js
const buffer = new ArrayBuffer(8);let uint8 = new Uint8Array(buffer);uint8.length; // 8 (バッファーの長さと一致)uint8 = new Uint8Array(buffer, 1, 5);uint8.length; // 5 (Uint8Array の構築の際に指定された通り)uint8 = new Uint8Array(buffer, 2);uint8.length; // 6 (構築された Uint8Array のオフセットによる)

仕様書

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

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp