let url = new URL("https://example.com?foo=1&bar=2");
let params = new URLSearchParams(url.search);
// Add a third parameter.
params.set("baz", 3);
params.toString(); // "foo=1&bar=2&baz=3"URLSearchParams: set() method / notebook
URLSearchParams: set() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.