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.