Categories
JavaScript Answers

How to convert uint8 array to base64 encoded string with JavaScript?

Spread the love

To convert uint8 array to base64 encoded string with JavaScript, we use the Buffer.from method.

For instance, we write

const u8 = new Uint8Array([65, 66, 67, 68]);
const b64 = Buffer.from(u8).toString("base64");

to call Buffer.from with the u8 Uint8Array to convert it to a buffer.

Then we call toString with 'base64' to convert it to a base64 string.

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 *