Name a few common TypedArray types and their byte sizes.
Short answer
Int8Array uses 1 byte per element, Int16Array uses 2, Float64Array uses 8. JS also has Uint8Array, Uint16Array, Int32Array, Uint32Array, Float32Array, and BigInt64Array/BigUint64Array for 64-bit integers.
Advertisement
AModel answer
Int8Array uses 1 byte per element, Int16Array uses 2, Float64Array uses 8. JS also has Uint8Array, Uint16Array, Int32Array, Uint32Array, Float32Array, and BigInt64Array/BigUint64Array for 64-bit integers.
new Int8Array(1).BYTES_PER_ELEMENT; // 1
new Int16Array(1).BYTES_PER_ELEMENT; // 2
new Float64Array(1).BYTES_PER_ELEMENT; // 8Real-world example
Choosing Uint8Array vs Float64Array matters a lot for memory usage on large binary datasets.
Likely follow-ups
- What happens if you assign a value outside a TypedArray's range?
Related topics