JavaScript URLSearchParams append() Tutorial

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

JavaScript URLSearchParams append() Method

The `append()` method is used to add a new entry (key/value) to the end of a query that we’ve created via the `URLSearchParams` constructor.

URLSearchParams append() Method Syntax:

URLSearchParams.append(name, value)

URLSearchParams append() Method Parameter:

The method takes two arguments:

  • The first argument is the key to the new parameter.
  • The second argument is the value of the key.

URLSearchParams append() Method Return Value:

The method does not return a value.

Example: using URLSearchParams append() method in JavaScript

const searchParams = new URLSearchParams("?name=John&lastName=Doe&[email protected]&address=Mars");

searchParams.append("id","000000");

console.log(searchParams);

Output:

name=John&lastName=Doe&[email protected]&address=Mars&id=000000
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies