Skip to main content
TextDecoder - Encoding - Web documentation
interface TextDecoder
Private

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

Examples

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"

Methods

decode(
input?: BufferSource,
): string

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