| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex | [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 toHex() method of Uint8Array instances returns a hex-encoded string based on the data in this Uint8Array object.
This method creates strings from a byte array. To convert individual numbers into hex, use the Number.prototype.toString() method with radix set to 16 instead.
toHex()
None.
A hex-encoded string representing the data in the Uint8Array.
This example encodes data from a Uint8Array into a hex string.
const uint8Array = new Uint8Array([202, 254, 208, 13]);
console.log(uint8Array.toHex()); // "cafed00d"
const data = new Uint8Array([255, 0, 0, 0, 255, 0, 0, 0, 255]);
for (let i = 0; i < data.length; i += 3) {
console.log(data.slice(i, i + 3).toHex());
}
// "ff0000"
// "00ff00"
// "0000ff"
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-uint8array.prototype.tohex |
Uint8Array.prototype.toHex in core-jsUint8Array.prototype.toHexUint8ArrayUint8Array.fromHex()Uint8Array.prototype.setFromHex()Number.prototype.toString()This page was last modified on Jul 15, 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 |