• {URLSearchParams}

    获取表示 URL 查询参数的 [URLSearchParams] 对象。 This property is read-only but the URLSearchParams object it provides can be used to mutate the URL instance; to replace the entirety of query parameters of the URL, use the [url.search][] setter. See [URLSearchParams][] documentation for details.

    Use care when using .searchParams to modify the URL because, per the WHATWG specification, the URLSearchParams object uses different rules to determine which characters to percent-encode. For instance, the URL object will not percent encode the ASCII tilde (~) character, while URLSearchParams will always encode it:

    1. const myUrl = new URL('https://example.org/abc?foo=~bar');
    2. console.log(myUrl.search); // prints ?foo=~bar
    3. // Modify the URL via searchParams...
    4. myUrl.searchParams.sort();
    5. console.log(myUrl.search); // prints ?foo=%7Ebar