To answer the original question: here is how you decode utf-8 in javascript:

http://ecmanaut.blogspot.ca/2006/07/encoding-decoding-utf8-in-javascript.html

Specifically,

function encode_utf8(s) {
  return unescape(encodeURIComponent(s));
}

function decode_utf8(s) {
  return decodeURIComponent(escape(s));
}

We have been using this in our production code for 6 years, and it has worked flawlessly.

Note, however, that escape() and unescape() are deprecated. See this.

Answer from CpnCrunch on Stack Overflow
🌐
GitHub
github.com › mathiasbynens › utf8.js
GitHub - mathiasbynens/utf8.js: A robust JavaScript implementation of a UTF-8 encoder/decoder, as defined by the Encoding Standard. · GitHub
utf8.js is a well-tested UTF-8 encoder/decoder written in JavaScript. Unlike many other JavaScript solutions, it is designed to be a proper UTF-8 encoder/decoder: it can encode/decode any scalar Unicode code point values, as per the Encoding ...
Author   mathiasbynens
🌐
GitHub
gist.github.com › chrisveness › bcb00eb717e6382c5608
Utf8 string encode/decode using regular expressions · GitHub
str="\\320\\223"+String.fromCodePoint(0x1F60E)+"..."; Utf8Decode(Utf8Encode(str).replace(/\\[0-9][0-9][0-9]/g,function(s){return String.fromCharCode(parseInt(s.substr(1),8));}))
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › TextDecoder
TextDecoder - Web APIs | MDN
June 28, 2025 - const utf8decoder = new TextDecoder(); // default 'utf-8' const encodedText = new Uint8Array([240, 160, 174, 183]); const output = document.querySelector("#output"); const decodeButton = document.querySelector("#decode"); decodeButton.addEventListener("click", () => { output.textContent = utf8decoder.decode(encodedText); }); const resetButton = document.querySelector("#reset"); resetButton.addEventListener("click", () => { window.location.reload(); }); In this example, we decode the Russian text "Привет, мир!", which means "Hello, world."
🌐
DEV Community
dev.to › emnudge › decoding-utf-8-3947
Decoding UTF-8 - DEV Community
May 16, 2021 - I recently went through a month's worth of research into unicode for an article and then subsequent video on variable names. JavaScript uses UTF-16 and I put some more specific info into the extra video, rather than the main video. I'd advise watching it if you're curious. I was recently asked about UTF-8 ...
🌐
Stegriff
stegriff.co.uk › upblog › base64-encode-and-decode-unicode-utf-8-strings-in-javascript-and-net
Base64 Encode and Decode Unicode (UTF-8) strings in JavaScript and .Net - SteGriff
MDN has an excellent code sample for making this work with what they label UCS-2, but the original source labels as UTF-8. Hmm… in any case, it makes it safe for Unicode strings instead of just ASCII: ... // ucs-2 string to base64 encoded ascii function utoa(str) { return window.btoa(unescape(encodeURIComponent(str))); } // base64 encoded ascii to ucs-2 string function atou(str) { return decodeURIComponent(escape(window.atob(str))); }
🌐
Mother Eff
mothereff.in › utf-8
UTF-8 encoder/decoder
This tool uses utf8.js to UTF-8-encode any string you enter in the ‘decoded’ field, or to decode any UTF-8-encoded string you enter in the ‘encoded’ field.
🌐
npm
npmjs.com › package › utf8
utf8 - npm
December 4, 2017 - utf8.js is a well-tested UTF-8 encoder/decoder written in JavaScript. Unlike many other JavaScript solutions, it is designed to be a proper UTF-8 encoder/decoder: it can encode/decode any scalar Unicode code point values, as per the Encoding ...
      » npm install utf8
    
Published   Dec 04, 2017
Version   3.0.0
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
Find elsewhere
🌐
GitHub
github.com › Benzinga › utf8js
GitHub - Benzinga/utf8js: Fast UTF-8 encoding/decoding for browsers and Node.
To be specific, utf8.js deals with the conversion between UTF-16 DOMStrings and UTF-8 TypedArrays. There are plenty of existing UNICODE libraries on npm, why write a new one? Well, many existing libraries do not handle large amounts of data well. When dealing with strings or arrays of over 100 MiB of data, transforming the string multiple times is not wise. In fact, it is surprisingly difficult for JavaScript code to construct large strings in the first place, without running out of memory.
Author   Benzinga
🌐
Webtoolkit
webtoolkit.info › javascript_utf8.html
Javascript UTF-8 - Javascript tutorial with example source code
November 17, 2013 - The encoding known today as UTF-8 was invented by Ken Thompson. UTF-8 is a variable-length character encoding for Unicode. It can represent any character in the Unicode standard, yet is backwards compatible with ASCII. Use this Javascript to encode decode UTF-8 data.
🌐
Honeybadger
honeybadger.io › blog › encode-javascript
The character encoding cheat sheet for JS developers - Honeybadger Developer Blog
September 21, 2023 - Next, we create a new string called str by decoding the buf buffer using the utf-8 encoding with the iconv.decode function. Finally, we log the str string to the console using the console.log function. When working with character encoding in JavaScript, there are a few best practices to keep in mind:
🌐
CodePen
codepen.io › piotezaza › pen › BvvMRm
Encode VS Decode UTF8 JavaScript
// ----- FUNCTIONS ----- // // ENCODE UTF8 function encode_utf8(s) { return unescape(encodeURIComponent(s)); } // DECODE UTF8 function decode_utf8(s) { return decodeURIComponent(escape(s)); } // ----- ENCODE & DECODE ----- // // ENCODE let from_1 = 'éàçè'; let result_1 = encode_utf8(from_1); $('.encode').html(result_1) // DECODE let from_2 = 'éà çè'; let result_2 = decode_utf8(from_2); $('.decode').html(result_2)
🌐
JSFiddle
jsfiddle.net › onigetoc › QmT59
javascript utf8 encode-decode - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
🌐
GitHub
gist.github.com › tudisco › 309475 › 17ee5e8ede2ee5464f90d1e86820215213833116
javascript utf8 encode and decode · GitHub
Learn more about bidirectional Unicode characters ... This solution doesn’t work correctly for astral symbols. e.g. UTF8.encode('\uD834\uDF06'). ... The result should be F0 9D 8C 86. // …but with the current implementation: UTF8.encode('\uD834\uDF06') == '\xF0\x9D\x8C\x86' // false ... Decoder with full Unicode support: https://gist.github.com/pascaldekloe/62546103a1576803dade9269ccf76330
🌐
Node.js
nodejs.org › api › string_decoder.html
String decoder | Node.js v26.5.0 Documentation
import { StringDecoder } from 'node:string_decoder'; import { Buffer } from 'node:buffer'; const decoder = new StringDecoder('utf8'); const cent = Buffer.from([0xC2, 0xA2]); console.log(decoder.write(cent)); // Prints: ¢ const euro = Buffer.from([0xE2, 0x82, 0xAC]); console.log(decoder.write(euro)); // Prints: € const { StringDecoder } = require('node:string_decoder'); const decoder = new StringDecoder('utf8'); const cent = Buffer.from([0xC2, 0xA2]); console.log(decoder.write(cent)); // Prints: ¢ const euro = Buffer.from([0xE2, 0x82, 0xAC]); console.log(decoder.write(euro)); // Prints: €
🌐
Blogger
ecmanaut.blogspot.com › 2006 › 07 › encoding-decoding-utf8-in-javascript.html
ecmanaut: Encoding / decoding UTF8 in javascript
From time to time it has somewhat annoyed me that UTF8 (today's most common Unicode transport encoding, recommended by the IETF) conversion is not readily available in browser javascript. It really is, though, I realized today: function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } 2012 Update: Monsur Hossain took a moment to explain how and why this works.