What You'll Learn
You'll learn how to read and write individual elements in typed arrays using the same bracket notation you already know from regular arrays.
Working with Typed Array Elements
Even though typed arrays have special numeric restrictions and are backed by raw binary memory (the ArrayBuffer), accessing and modifying their elements feels completely natural. You use the same bracket notation ([]) that you've used throughout JavaScript with regular arrays.
Reading Elements
To read a value, use the index in square brackets:
const int8 = new Int8Array([10, 20, 30, 40]);
console.log(int8[0]); // 10
console.log(int8[2]); // 30
console.log(int8[5]); // undefined (out of bounds)
Writing Elements
To modify a value, assign to an index just like any array:
const uint16 = new Uint16Array(3);
uint16[0] = 100;
uint16[1] = 200;
uint16[2] = 300;
console.log(uint16); // Uint16Array(3) [100, 200, 300]
Type Enforcement Happens Automatically
The typed array will coerce values to fit its numeric type. If you try to store something out of range, it wraps or clamps:
const uint8 = new Uint8Array(2);
uint8[0] = 255; // fits perfectly
uint8[1] = 256; // wraps to 0 (256 % 256)
console.log(uint8); // Uint8Array(2) [255, 0]
The Familiar Interface
This consistency is by design. Typed arrays behave like arrays where it matters most—element access—so you can work with binary data using patterns you already know.
Key Takeaway: Typed arrays use standard bracket notation for reading and writing elements, making them feel like regular arrays despite their binary foundation and numeric type restrictions.