Categories
JavaScript Answers

How to decode a string with escaped Unicode with JavaScript?

Spread the love

Sometimes, we want to decode a string with escaped Unicode with JavaScript.

In this article, we’ll look at how to decode a string with escaped Unicode with JavaScript.

How to decode a string with escaped Unicode with JavaScript?

To decode a string with escaped Unicode with JavaScript, we can use the decodeURIComponent function.

For instance, we write

const unescaped = decodeURIComponent(
  JSON.parse('"http\\u00253A\\u00252F\\u00252Fexample.com"')
);

to call decodeURIComponent with the string parsed with JSON.parse.

Then we the Unicode string will be unerscaped by decodeURIComponent.

Conclusion

To decode a string with escaped Unicode with JavaScript, we can use 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 *