JavaScript URLSearchParams delete() Tutorial

In this section, we will learn what the URLSearchParams delete() method is and how to use it in JavaScript.

JavaScript URLSearchParams delete() Method

The `delete()` method is used to remove the given key, and all its associated values from the target query. This means if the key is repeated in the query like two or more times, when we call the `delete()` method on that key, all the entries that have the key will be removed.

URLSearchParams delete() Method Syntax:

URLSearchParams.delete(name)

URLSearchParams delete() Method Parameter:

The method takes one argument and that is the name of the key which we want it to be removed from the query.

URLSearchParams delete() Method Return Value:

The method does not return a value.

Example: JavaScript remove url parameters

const searchParams = new URLSearchParams("?name=John&lastName=Doe&address=Mars&name=Omid");

searchParams.delete("name");

console.log(searchParams);

Output:

lastName=Doe&address=Mars

Leave a Reply