encode

fun encode(input: String = definedExternally): Uint8Array<ArrayBuffer>(source)

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

MDN Reference