urlSearchparams.get code example
Example 1: javascript urlsearchparams to object
var search = location.search.substring(1);
JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
Example 2: 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"});