How to decode a URI
Rohit Kumawat

Rohit Kumawat @ip127001

About: Helping startups to build world class products. I love web, Javascript and F.R.I.E.N.D.S.

Location:
Jaipur, Rajasthan, India
Joined:
Apr 8, 2020

How to decode a URI

Publish Date: Jan 7 '21
12 0

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.

Comments 0 total

    Add comment