Categories
JavaScript Answers

How to store a byte array in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *