Skip to main content

TextDecoder

interface TextDecoder

Represents a decoder for a specific text encoding, allowing you to convert binary data into a string given the encoding.

Jump to heading

Example 1

const decoder = new TextDecoder('utf-8');
const buffer = new Uint8Array([72, 101, 108, 108, 111]);
const decodedString = decoder.decode(buffer);
console.log(decodedString); // Outputs: "Hello"

Turns binary data, often in the form of a Uint8Array, into a string given the encoding.

Back to top