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 |
浏览器兼容性
加载中…