ArrayBuffer.prototype.byteLength
byteLength 訪問器屬性,是 例項的屬性,用於返回此 ArrayBuffer 的長度(以位元組為單位)。ArrayBuffer
試一試
// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(8);
// Use byteLength to check the size
const bytes = buffer.byteLength;
console.log(bytes);
// Expected output: 8
描述
byteLength 屬性是一個訪問器屬性,其 set 訪問器函式為 undefined,這意味著您只能讀取此屬性。該值在陣列構造時設定,並且無法更改。如果此 ArrayBuffer 已被分離,則此屬性將返回 0。
示例
使用 byteLength
js
const buffer = new ArrayBuffer(8);
buffer.byteLength; // 8
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-get-arraybuffer.prototype.bytelength |
瀏覽器相容性
載入中…