DEV Community

loading...
Cover image for How to decode a URI

How to decode a URI

ip127001 profile image Rohit Kumawat ・1 min read

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
Enter fullscreen mode Exit fullscreen mode

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.

Discussion (0)

pic
Editor guide