How to pass a parameter in URL in JavaScript?

To pass a parameter in URL in JavaScript, create a URL object, then add the parameter with url.searchParams.append(), finally convert back to string with url.toString().

Here's how you do it:

const url = new URL('');
url.searchParams.append('param', 'value');
const urlString = url.toString();


// go to:
window.location.href = urlString;