SharedArrayBuffer.prototype.byteLength

Baseline 已廣泛支援

此功能已成熟,可在多種裝置和瀏覽器版本上使用。自 2021 年 12 月以來,它已在所有瀏覽器中可用。

byteLength 訪問器屬性,屬於 SharedArrayBuffer 例項,返回此 SharedArrayBuffer 的長度(以位元組為單位)。

試一試

// Create a SharedArrayBuffer with a size in bytes
const buffer = new SharedArrayBuffer(8);

console.log(buffer.byteLength);
// Expected output: 8

描述

byteLength 屬性是一個訪問器屬性,其 set 訪問器函式為 undefined,這意味著您只能讀取此屬性。該值在共享陣列構造時建立,且無法更改。

示例

使用 byteLength

js
const sab = new SharedArrayBuffer(1024);
sab.byteLength; // 1024

規範

規範
ECMAScript® 2026 語言規範
# sec-get-sharedarraybuffer.prototype.bytelength

瀏覽器相容性

另見