Categories
JavaScript Answers

How to convert special UTF-8 chars to their iso-8859-1 equivalent using JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *