TypedArray.prototype.byteLength

byteLength 访问器属性表示类型化数组的长度(字节数)。

语法

typedarray.byteLength

描述

byteLength 是一个访问器属性,它的 set 访问器函数是 undefined,意思是你只能够读取这个属性。它的值在 TypedArray 构造时建立,不能被修改。如果 TypedArray 没有指定 byteOffset 或者 length,会返回所引用的 ArrayBufferlengthTypedArray 是这里的 TypedArray 对象之一。

示例

使用 byteLength 属性

js

var buffer = new ArrayBuffer(8);

var uint8 = new Uint8Array(buffer);
uint8.byteLength; // 8 (符合 buffer 的 byteLength)

var uint8 = new Uint8Array(buffer, 1, 5);
uint8.byteLength; // 5 (在 Uint8Array 构造时指定)

var uint8 = new Uint8Array(buffer, 2);
uint8.byteLength; // 6 (根据被构造的 Uint8Array 的 offset)

规范

Specification
ECMAScript Language Specification
# sec-get-%typedarray%.prototype.bytelength

浏览器兼容性

BCD tables only load in the browser

另见