Skip to content

Emptying URLSearchParams causes unwanted "?" char #10480

@stevenvachon

Description

@stevenvachon
const url = new URL("http://domain?var=1&var=2&var=3");
const params = Array.from(url.searchParams);

// There is no `.clear()`
for (let param of url.searchParams) {
  url.searchParams.delete( param[0] );
}

console.log(url.href) //-> http://domain/?

url.search = url.searchParams.toString();

console.log(url.href) //-> http://domain/

Tested in Chrome and both correctly log the same (second) value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    urlIssues and PRs related to the legacy built-in url module.whatwg-urlIssues and PRs related to the WHATWG URL implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions