interface TextEncoder
extends TextEncoderCommon
Methods Jump to heading
Jump to headingencode(input?: string): Uint8Array
Returns the result of running UTF-8's encoder.
Jump to headingencodeInto(input: string,dest: Uint8Array,): TextEncoderEncodeIntoResult
Allows you to convert a string into binary data (in the form of a Uint8Array) given the encoding.
Examples Jump to heading
Jump to heading
Example 1
Example 1
const encoder = new TextEncoder();
const str = "Hello";
const encodedData = encoder.encode(str);
console.log(encodedData); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]
Methods Jump to heading
Jump to headingencode(input?: string): Uint8Array
Turns a string into binary data (in the form of a Uint8Array) using UTF-8 encoding.
Jump to headingencodeInto(input: string,dest: Uint8Array,): TextEncoderEncodeIntoResult
Encodes a string into the destination Uint8Array and returns the result of the encoding.