const buf = new ArrayBuffer(16);const u8 = new Uint8Array(buf);u8.set([1,2,3,4]);
API
Description
new ArrayBuffer(n)
Allocate n bytes
buf.byteLength
Size
buf.slice(s,e)
Copy subrange
buf.transfer()NEW
Zero-copy ownership transfer
4. Using Typed Arrays
View
Range
Int8Array
-128..127
Uint8Array
0..255
Uint8ClampedArray
0..255 (saturating)
Int16/Uint16
±32K / 0..65K
Int32/Uint32
±2.1B / 0..4.2B
Float32/Float64
IEEE 754
BigInt64/BigUint64
64-bit ints
5. Using DataView
Example: Endian control
const v = new DataView(buf);v.setUint32(0, 0xCAFEBABE, false); // big-endianconst n = v.getUint32(0, false);const f = v.getFloat32(4, true); // little-endian