TypedArray.prototype.byteLength

byteLength アクセサープロパティは、型付き配列の長さを(バイト単位で)表します。

試してみましょう

解説

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

byteLength プロパティの使用

js

const buffer = new ArrayBuffer(8);

const uint8 = new Uint8Array(buffer);
uint8.byteLength; // 8 (matches the byteLength of the buffer)

const uint8newLength = new Uint8Array(buffer, 1, 5);
uint8newLength.byteLength; // 5 (as specified when constructing the Uint8Array)

const uint8offSet = new Uint8Array(buffer, 2);
uint8offSet.byteLength; // 6 (due to the offset of the constructed Uint8Array)

仕様書

Specification
ECMAScript Language Specification
# sec-get-%typedarray%.prototype.bytelength

ブラウザーの互換性

BCD tables only load in the browser

関連情報