Get to know MDN better
Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The Uint8Array.fromHex() static method creates a new Uint8Array object from a hexadecimal string.
This method parses the string into a byte array. To convert the string into a single number, use the parseInt() function with radix set to 16 instead.
A hexadecimal string encoding bytes to convert to a Uint8Array. The string must:
A new Uint8Array object containing the decoded bytes from the hexadecimal string.
Thrown if the input string contains characters outside the hex alphabet, or its length is odd.
TypeErrorThrown if the input string is not a string.
This example decodes a hexadecimal string into a Uint8Array.
Uppercase characters are also supported:
| ECMAScript® 2027 Language Specification # sec-uint8array.fromhex |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.