| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromHex | [Back] [Original] |
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.
Uint8Array.fromHex(string)
stringA hexadecimal string encoding bytes to convert to a Uint8Array. The string must:
Uint8Array.prototype.setFromBase64()).A new Uint8Array object containing the decoded bytes from the hexadecimal string.
SyntaxErrorThrown 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.
const hexString = "cafed00d";
const bytes = Uint8Array.fromHex(hexString);
console.log(bytes); // Uint8Array [ 202, 254, 208, 13 ]
Uppercase characters are also supported:
const hexString = "CAFEd00d";
const bytes = Uint8Array.fromHex(hexString);
console.log(bytes); // Uint8Array [ 202, 254, 208, 13 ]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-uint8array.fromhex |
Uint8Array.fromHex in core-jsUint8Array.fromHexUint8ArrayUint8Array.prototype.setFromHex()Uint8Array.prototype.toHex()parseInt()This page was last modified on Jul 10, 2025 by MDN contributors.
Uint8ArrayTypedArrayObject/FunctionBigInt64ArrayBigUint64ArrayFloat16ArrayFloat32ArrayFloat64ArrayInt8ArrayInt16ArrayInt32ArrayUint8ClampedArrayUint16ArrayUint32ArrayYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |