TypedArray.BYTES_PER_ELEMENT
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Juli 2015.
Die statische Dateneigenschaft TypedArray.BYTES_PER_ELEMENT
repräsentiert die Größe in Bytes jedes Elements in einem typisierten Array.
Probieren Sie es aus
console.log(Float64Array.BYTES_PER_ELEMENT);
// Expected output: 8
console.log(Int8Array.BYTES_PER_ELEMENT);
// Expected output: 1
Wert
Eine Zahl, deren Wert vom Typ des TypedArray
abhängt.
Eigenschaften von TypedArray.BYTES_PER_ELEMENT | |
---|---|
Schreibbar | nein |
Aufzählbar | nein |
Konfigurierbar | nein |
Beschreibung
TypedArray
-Objekte unterscheiden sich in der Anzahl von Bytes pro Element und in der Art, wie die Bytes interpretiert werden. Die Konstante BYTES_PER_ELEMENT
enthält die Anzahl von Bytes, die jedes Element im angegebenen TypedArray
hat.
Die Eigenschaft BYTES_PER_ELEMENT
ist sowohl eine Instanzeigenschaft als auch eine statische Eigenschaft. Sie ist sowohl in Konstruktoren der TypedArray
-Unterklassen als auch in Instanzen dieser Konstruktoren verfügbar.
Als Instanzeigenschaft ist BYTES_PER_ELEMENT
im prototype
des Konstruktors definiert.
console.log(Object.hasOwn(Int8Array.prototype, "BYTES_PER_ELEMENT")); // true
Beispiele
>Verwendung von BYTES_PER_ELEMENT
Als statische Eigenschaft:
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
Float16Array.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
Als Instanzeigenschaft:
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 Float16Array([]).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
Spezifikationen
Specification |
---|
ECMAScript® 2026 Language Specification> # sec-typedarray.bytes_per_element> |
Browser-Kompatibilität
Loading…
Siehe auch
- JavaScript typisierte Arrays Leitfaden
TypedArray