JavaScript: replace hexadecimal character

I have a line such as "%2Fu%2F2069290%2F"in JavaScript (extracted from a web page). How to get a readable version of this line?

+5
source share
4 answers

Short version . Use decodeURIComponent().

Longer version . You can use JavaScript in older versions unescape(), but it was deprecated since it only works for the LATIN1 / ISO8859-1 code, so you really want to use decodeURIComponent()one that is supported by all modern browsers.

 var c = decodeURIComponent("%2Fu%2F2069290%2F"));
+7
source
alert(decodeURIComponent("%2Fu%2F2069290%2F"));
+2
source

unescape(), :

alert(unescape("%2Fu%2F2069290%2F"));
0

unescape()?

0

All Articles