TextEncoder
interface
interface TextEncoder extends TextEncoderCommonAllows you to convert a string into binary data (in the form of a Uint8Array) given the encoding.
Example
const encoder = new TextEncoder();
const str = "Hello";
const encodedData = encoder.encode(str);
console.log(encodedData); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]
variable
var TextEncoder: { … }The constructor object for TextEncoder, used to create an
encoder that turns strings into UTF-8 encoded bytes.
Constructors
constructor
new TextEncoder(): TextEncoderProperties
prototype
readonly prototype: TextEncoderMethods
encode
encode(input?: string): Uint8Array<ArrayBuffer>Turns a string into binary data (in the form of a Uint8Array) using UTF-8 encoding.
encodeInto
encodeInto(input: string, dest: Uint8Array<ArrayBufferLike>): TextEncoderEncodeIntoResultEncodes a string into the destination Uint8Array and returns the result of the encoding.