Spec-Zone.ru › JavaScript

Uint8Array.prototype.toHex()

Baseline Newly available

This feature works across the latest devices and browser versions. This feature might not work in older devices or browser versions. It's been available across browsers since September 2025.

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.

Syntax

toHex()

Parameters

None.

Return value

A hex-encoded string representing the data in the Uint8Array.

Examples

Encoding binary data

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"

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-uint8array.prototype.tohex

Browser compatibility

Desktop Mobile Server
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on iOS Samsung Internet WebView Android WebView on iOS Bun Deno Node.js
toHex
140
140
133
124
18.2
140
133
92
18.2
30.0
140
18.2
1.1.22
2.5.0
25.0.0

See also

  • Polyfill of Uint8Array.prototype.toHex in core-js
  • es-shims polyfill of Uint8Array.prototype.toHex
  • Uint8Array
  • Uint8Array.fromHex()
  • Uint8Array.prototype.setFromHex()
  • Number.prototype.toString()

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API