TypedArray.BYTES_PER_ELEMENT

TypedArray.BYTES_PER_ELEMENT 静态数据属性表示类型化数组中每个元素的大小(以字节为单位)。

¥The TypedArray.BYTES_PER_ELEMENT static data property represents the size in bytes of each element in a typed array.

Try it

¥Value

一个数字,其值取决于 TypedArray 的类型。

¥A number whose value depends on the type of TypedArray.

Property attributes of TypedArray.BYTES_PER_ELEMENT
Writable no
Enumerable no
Configurable no

描述

¥Description

TypedArray 对象在每个元素的字节数以及解释字节的方式方面彼此不同。BYTES_PER_ELEMENT 常量包含给定 TypedArray 中每个元素的字节数。

¥TypedArray objects differ from each other in the number of bytes per element and in the way the bytes are interpreted. The BYTES_PER_ELEMENT constant contains the number of bytes each element in the given TypedArray has.

BYTES_PER_ELEMENT 属性既是实例属性又是静态属性。它可用于 TypedArray 子类构造函数和这些构造函数的实例。

¥The BYTES_PER_ELEMENT property is both an instance property and a static property. It's available on both TypedArray subclass constructors and on instances of those constructors.

作为实例属性,BYTES_PER_ELEMENT 是在构造函数的 prototype 上定义的。

¥As an instance property, BYTES_PER_ELEMENT is defined on the constructor's prototype.

js
console.log(Object.hasOwn(Int8Array.prototype, "BYTES_PER_ELEMENT")); // true

示例

¥Examples

使用 BYTES_PER_ELEMENT

¥Using BYTES_PER_ELEMENT

作为静态属性:

¥As a static property:

js
Int8Array.BYTES_PER_ELEMENT; // 1
Uint8Array.BYTES_PER_ELEMENT; // 1
Uint8ClampedArray.BYTES_PER_ELEMENT; // 1
Int16Array.BYTES_PER_ELEMENT; // 2
Uint16Array.BYTES_PER_ELEMENT; // 2
Int32Array.BYTES_PER_ELEMENT; // 4
Uint32Array.BYTES_PER_ELEMENT; // 4
Float32Array.BYTES_PER_ELEMENT; // 4
Float64Array.BYTES_PER_ELEMENT; // 8
BigInt64Array.BYTES_PER_ELEMENT; // 8
BigUint64Array.BYTES_PER_ELEMENT; // 8

作为实例属性:

¥As an instance property:

js
new Int8Array([]).BYTES_PER_ELEMENT; // 1
new Uint8Array([]).BYTES_PER_ELEMENT; // 1
new Uint8ClampedArray([]).BYTES_PER_ELEMENT; // 1
new Int16Array([]).BYTES_PER_ELEMENT; // 2
new Uint16Array([]).BYTES_PER_ELEMENT; // 2
new Int32Array([]).BYTES_PER_ELEMENT; // 4
new Uint32Array([]).BYTES_PER_ELEMENT; // 4
new Float32Array([]).BYTES_PER_ELEMENT; // 4
new Float64Array([]).BYTES_PER_ELEMENT; // 8
new BigInt64Array([]).BYTES_PER_ELEMENT; // 8
new BigUint64Array([]).BYTES_PER_ELEMENT; // 8

规范

Specification
ECMAScript Language Specification
# sec-typedarray.bytes_per_element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看