JavaScript typed arrays split the implementation into buffers and views. A buffer (implemented by the
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arraysArrayBuffer
object) is an object representing a chunk of data; it has no format to speak of and offers no mechanism for accessing its contents. In order to access the memory contained in a buffer, you need to use a view. A view provides a context — that is, a data type, starting offset, and the number of elements — that turns the data into a typed array.

Type | Value Range | Size in bytes | Description | Web IDL type | Equivalent C type |
---|---|---|---|---|---|
Int8Array | -128 to 127 | 1 | 8-bit two’s complement signed integer | byte | int8_t |
Uint8Array | 0 to 255 | 1 | 8-bit unsigned integer | octet | uint8_t |
Uint8ClampedArray | 0 to 255 | 1 | 8-bit unsigned integer (clamped) | octet | uint8_t |
Int16Array | -32768 to 32767 | 2 | 16-bit two’s complement signed integer | short | int16_t |
Uint16Array | 0 to 65535 | 2 | 16-bit unsigned integer | unsigned short | uint16_t |
Int32Array | -2147483648 to 2147483647 | 4 | 32-bit two’s complement signed integer | long | int32_t |
Uint32Array | 0 to 4294967295 | 4 | 32-bit unsigned integer | unsigned long | uint32_t |
Float32Array | 1.2 ×10-38 to 3.4 ×1038 | 4 | 32-bit IEEE floating point number (7 significant digits e.g., 1.123456 ) | unrestricted float | float |
Float64Array | 5.0 ×10-324 to 1.8 ×10308 | 8 | 64-bit IEEE floating point number (16 significant digits e.g., 1.123...15 ) | unrestricted double | double |
BigInt64Array | -263 to 263-1 | 8 | 64-bit two’s complement signed integer | bigint | int64_t (signed long long) |
BigUint64Array | 0 to 264-1 | 8 | 64-bit unsigned integer | bigint | uint64_t (unsigned long long) |
Example
> u8view
Uint8Array [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
> u32view
Uint32Array [ 0, 0, 0, 0 ]
> u8view[0] = 255
255
> u32view[0]
255
// 257 is greater than 255, will become 1
// 1[00000001] = 257 => 1
// 1[00000000] = 256 => 0
> u8view[1] = 257
257
> u8view[1]
1
// 32 byte view, the first element is 256 (u8view[1]) + 255(u8view[0]) = 511
> u32view[0]
511
> u8view[3] = 1
1
// 32 byte view, the first element is (2^24 + 1) + (2^16 * 0) + (2^8 + 1) + 255
// 16777216 + 0 + 256 + 255 = 16777727
> u32view[0]
16777727
> u8view
Uint8Array [ 255, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
> u32view
Uint32Array [ 16777727, 0, 0, 0 ]