How to Encode an Email in JavaScript for Use in the Query String?

To use an email in the query string component of a URL, you can encode it using the encodeURIComponent() function in JavaScript. This would encode all characters except A-Z a-z 0-9 - _ . ! ~ * ' ( ). For example:

const email = '[email protected]';
const encodedEmail = encodeURIComponent(email);
const url = `${encodedEmail}`;

console.log(url); //

Hope you found this post useful. It was published . Please show your love and support by sharing this post.