Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

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

DataView.prototype.byteLength

BaselineWidely available

byteLength アクセサープロパティは、このビューのArrayBuffer またはSharedArrayBuffer の先頭から長さを (バイト単位で) 表します。

試してみましょう

// Create an ArrayBuffer with a size in bytesconst buffer = new ArrayBuffer(16);const view1 = new DataView(buffer);const view2 = new DataView(buffer, 12, 4); // From byte 12 for the next 4 bytesconsole.log(view1.byteLength + view2.byteLength); // 16 + 4// Expected output: 20

解説

byteLength プロパティは、設定アクセサー関数がundefined である、すなわち読み取りのみができるアクセサープロパティです。この値はDataView が構築されたときに確立され、変更することができません。DataView がオフセットやbyteLength を指定していなかった場合は、参照されているArrayBuffer またはSharedArrayBufferbyteLength が返されます。

byteLength プロパティの使用

js
var buffer = new ArrayBuffer(8);var dataview = new DataView(buffer);dataview.byteLength; // 8 (matches the byteLength of the buffer)var dataview2 = new DataView(buffer, 1, 5);dataview2.byteLength; // 5 (as specified when constructing the DataView)var dataview3 = new DataView(buffer, 2);dataview3.byteLength; // 6 (due to the offset of the constructed DataView)

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-get-dataview.prototype.bytelength

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp