Docs

URL.prototype.search

The search parameters string, including the leading question mark.

Example

let url = new URL("https://example.com?foo=bar&baz=qux")
url.search
"?foo=bar&baz=qux"
let url = new URL("https://example.com")
url.search
""
let url = new URL("https://example.com")
url.search = "?a=1&b=2"
url.href
"https://example.com/?a=1&b=2"