Sometimes, we want to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript.
In this article, we’ll look at how to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript.
How to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript?
To convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript, we call the decodeURIComponent
function.
For instance, we write
const fixedString = decodeURIComponent(escape(utfString));
to call escape
to return an escaped version of the utfString
string.
Then we call decodeURIComponent
with the escaped string to convert it to the iso-8859-1 string.
Conclusion
To convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript, we call the decodeURIComponent
function.