Convert a base64 encoded string to an Uint8Array
Decode base64 into its byte values.
function base64ToBytes(base64) { return Array.from(atob(base64), char => char.charCodeAt(0)); }
Input & expected output
Input
"SGVsbG8="Expected output
[
72,
101,
108,
108,
111
]The edge case
Input
""Expected output
[]Know the limits
- Returns plain numbers so the lab can show them; wrap the result with Uint8Array.from in your code.
- Oveyon’s /v1/send takes attachment content as base64 (up to 20 attachments, 15 MB in total); decode only what you need to inspect.
The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.
Source & maintenance
Based on Convert a base64 encoded string to an uint8 array from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.
Returns plain byte values instead of a Uint8Array so results are JSON-representable; base64 alphabet and padding validated first. Original MDX retained as inert source evidence.
Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.
Keep exploring
- Capitalize a string — Uppercase the first Unicode code point and preserve the remaining text.
- Reverse a string — Reverse Unicode code points without splitting surrogate pairs.
- Check a palindrome — Compare a string with its code-point reversal.