このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
TypedArray.prototype.byteLength
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月.
byteLength はTypedArray のアクセサープロパティで、この型付き配列の長さを(バイト単位で)返します。
In this article
試してみましょう
// Create an ArrayBuffer with a size in bytesconst buffer = new ArrayBuffer(8);const uint8 = new Uint8Array(buffer, 2);console.log(uint8.byteLength);// Expected output: 6解説
byteLength プロパティは設定アクセサープロパティがundefined である、読み取り専用のアクセサープロパティです。値はTypedArray が構築されたときに確立し、変更することができません。TypedArray がbyteOffset やlength を指定していないなら、参照されているArrayBuffer のlength が返されます。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® 2026 Language Specification> # sec-get-%typedarray%.prototype.bytelength> |