v149 · javascript · covered on mdn
Uint8Array Base64 and Hex Methods
Six new methods on Uint8Array for converting raw bytes to and from base64 and hexadecimal strings without any third-party library — part of ECMAScript 2026 (TC39 Stage 4, archived October 2025).
this API is documented on MDN
MDN: Uint8Array.prototype.toBase64()
MDN documents all six methods with signatures, options, examples, and browser compatibility tables. The same namespace covers fromBase64, toHex, fromHex, setFromBase64, and setFromHex. gendn doesn't duplicate that reference here.
quick reference
| Method | Direction | Notes |
|---|---|---|
Uint8Array.prototype.toBase64(options?) | bytes → string | alphabet: "base64" | "base64url"; omitPadding: boolean |
Uint8Array.fromBase64(str, options?) | string → bytes | Creates new Uint8Array. lastChunkHandling: "loose" | "strict" | "stop-before-partial" |
Uint8Array.prototype.setFromBase64(str, options?) | string → existing bytes | Writes into existing array; returns { read, written } |
Uint8Array.prototype.toHex() | bytes → string | Lowercase hex, no options |
Uint8Array.fromHex(str) | string → bytes | Accepts upper- and lowercase; creates new Uint8Array |
Uint8Array.prototype.setFromHex(str) | string → existing bytes | Writes into existing array; returns { read, written } |
quick examples
const bytes = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
// Encode
bytes.toBase64(); // 'SGVsbG8='
bytes.toBase64({ omitPadding: true }); // 'SGVsbG8'
bytes.toBase64({ alphabet: 'base64url' }); // 'SGVsbG8='
bytes.toHex(); // '48656c6c6f'
// Decode
Uint8Array.fromBase64('SGVsbG8=');
// Uint8Array [72, 101, 108, 108, 111]
Uint8Array.fromHex('48656c6c6f');
// Uint8Array [72, 101, 108, 108, 111]
// Write into an existing buffer (useful for streaming)
const target = new Uint8Array(10);
const { read, written } = target.setFromBase64('SGVsbG8=');
// read: 8 (base64 chars consumed), written: 5 (bytes written)
Source: tc39/proposal-arraybuffer-base64 README.
shipped in
| Shipped in | Chrome 149 |
|---|---|
| Standard | ECMAScript 2026 (TC39 Stage 4) |
| ChromeStatus | chromestatus.com/feature/6281131254874112 |
| TC39 proposal | tc39/proposal-arraybuffer-base64 |