Skip to content

Instantly share code, notes, and snippets.

@rpivo
Created March 18, 2021 01:41
Show Gist options
  • Save rpivo/2234d2da3813710e8667df2f25d920e9 to your computer and use it in GitHub Desktop.
Save rpivo/2234d2da3813710e8667df2f25d920e9 to your computer and use it in GitHub Desktop.
Encoding & Decoding a String Using the TextEncoder & TextDecoder APIs

Encoding & Decoding a String Using the TextEncoder & TextDecoder APIs

const encoded = new TextEncoder().encode('foo')
const decoded = new TextDecoder().decode(encoded)
console.log({
  encoded,
  decoded,
})

Logs:

decoded: "foo"
encoded: Uint8Array(3) [102, 111, 111]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment