0 votes
in JavaScript by
How do you decode or encode a URL in JavaScript?

1 Answer

0 votes
by

encodeURI() function is used to encode an URL. This function requires a URL string as a parameter and return that encoded string. decodeURI() function is used to decode an URL. This function requires an encoded URL string as parameter and return that decoded string.

Note: If you want to encode characters such as / ? : @ & = + $ # then you need to use encodeURIComponent().

let uri = "employeeDetails?name=john&occupation=manager";
let encoded_uri = encodeURI(uri);
let decoded_uri = decodeURI(encoded_uri);

Related questions

0 votes
asked Oct 24, 2023 in JavaScript by DavidAnderson
0 votes
asked Feb 20 in JavaScript by DavidAnderson
...