How to decode a URI
Rohit Kumawat
Posted on January 7, 2021
I once found myself in a situation where the URI was changing by clicking on a
tag and href
was adding parameters like name=dev community
as a hash to make the page scrollable to a specific section. Basically, it was encoding the URI by adding a hash to it.
Now I need to decode that URI and extract the name from it. I tried several things but I forgot there is a native JavaScript method that decodes encoded URI.
decodeURI:
- native javascript method
- decodes encoded URI
Example:
const encodedURI = "https://example.com?name=dev%20community";
const result = decodeURI(encodedURI);
//https://example.com?name=dev community
Note: There is also a function in Javascript
encodeURI()
which encodes the URI.
Kudos to undraw for such great illustrations.
Thanks for reading the article. For more tech tweets Twitter.
💖 💪 🙅 🚩
Rohit Kumawat
Posted on January 7, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.