Convert a Uint8Array to a base64-encoded string.
This function works in both browser and Node.js environments. Uses btoa which is available in browsers and Node.js 16+.
The byte array to encode
A base64-encoded string
const bytes = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"toBase64(bytes); // "SGVsbG8=" Copy
const bytes = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"toBase64(bytes); // "SGVsbG8="
Convert a Uint8Array to a base64-encoded string.
This function works in both browser and Node.js environments. Uses btoa which is available in browsers and Node.js 16+.