new URLSearchParams() code example
Example 1: URLSearchParams(new URL(url).search)
var url = new URL('https://example.com?foo=1&bar=2');
var params = new URLSearchParams(url.search);
var params2 = new URLSearchParams("foo=1&bar=2");
var params2a = new URLSearchParams("?foo=1&bar=2");
var params3 = new URLSearchParams([["foo", "1"], ["bar", "2"]]);
var params4 = new URLSearchParams({"foo": "1", "bar": "2"});
Example 2: generate query string from urlsearchparams
URLSearchParams.toString()
Example 3: typescript read url search params
const product = urlParams.get('product')
console.log(product);
const color = urlParams.get('color')
console.log(color);
const newUser = urlParams.get('newuser')
console.log(newUser);