Uint8Array.prototype.toHex() - JavaScript | MDN
Syntax
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.
js
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 |