SharedArrayBuffer.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 December 2021.

SharedArrayBuffer 实例的 byteLength 访问器属性返回该 SharedArrayBuffer 的大小(以字节为单位)。

尝试一下

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

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

描述

byteLength 属性是一个访问器属性,它的设置访问器函数为 undefined,这意味着你只能读取该属性。该值在创建共享数组时就确定了,不能更改。

示例

使用 byteLength

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

规范

Specification
ECMAScript® 2025 Language Specification
# sec-get-sharedarraybuffer.prototype.bytelength

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
byteLength

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

参见