TextEncoder

The TextEncoder interface enables you to encode a JavaScript string using UTF-8.

MDN Reference

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open val encoding: String

Returns "utf-8".

Functions

Link copied to clipboard
fun encode(input: String = definedExternally): Uint8Array<ArrayBuffer>

The TextEncoder.encode() method takes a string as input, and returns a Uint8Array containing the string encoded using UTF-8.

Link copied to clipboard

The TextEncoder.encodeInto() method takes a string to encode and a destination Uint8Array to put resulting UTF-8 encoded text into, and returns an object indicating the progress of the encoding. This is potentially more performant than the encode() method — especially when the target buffer is a view into a Wasm heap.