The toString()
method of the URLSearchParams
interface returns a query string suitable for use in a URL.
Note: This method returns the query string without the question mark. This is different from window.location.search, which includes it.
A string, without the question mark. (Returns an empty string if no search parameters have been set.)
let url = new URL('https://example.com?foo=1&bar=2');
let params = new URLSearchParams(url.search);
params.append('foo', 4);
console.log(params.toString());
let url = new URL('https://example.com?foo=1&bar=2');
let params = url.searchParams;
let params = new URLSearchParams('foo=1&bar=2');