utf8.encode

Encodes the string as UTF-8 bytes.

Syntax

encode(string)

Parameters

Return value

A Uint8Array of bytes.

Example

utf8.encode("hello 🐥")
Uint8Array [104, 101, 108, 108, 111, 32, 240, 159, 144, 165]
// same as
new TextEncoder().encode("hello 🐥")
Uint8Array [104, 101, 108, 108, 111, 32, 240, 159, 144, 165]