Sometimes, we want to decode UTF-8 with JavaScript.
In this article, we’ll look at how to decode UTF-8 with JavaScript.
How to decode UTF-8 with JavaScript?
To decode UTF-8 with JavaScript, we use the decodeURIComponent
function.
For instance, we write
const decodeUtf8 = (s) => {
return decodeURIComponent(escape(s));
};
to define the decodeUtf8
function.
In it, we call escape
to return a escaped version of string s
.
And then we call decodeURIComponent
to decode the contents of the escaped string.
Conclusion
To decode UTF-8 with JavaScript, we use the decodeURIComponent
function.