How to store a byte array in JavaScript?

To store a byte array in JavaScript, we use the Unint8Array constructor.

For instance, we write

const array = new Uint8Array(100);
array[10] = 256;
console.log(array[10] === 0);

to create an Uint8Array array with 100 bytes.

Then we set the content of byte 11 to 256.

And then we check that its value is the same as 0, which is true since it’s 8 bits.