The urlSearchParams.append() is an inbuilt application programming interface of class URLSearchParams with in url module which is used to append the associate argument of name to value in this url search params object. Syntax :
urlSearchParams.append(name, value)
Parameter: This method accepts the following argument as a parameter.
- name : name of the argument.
- value : value for the particular argument.
Return Value :
This method has nothing to return. Below programs illustrates the use of urlSearchParams.append() Method: Example 1:
// node program to demonstrate the
// URLSearchParams.append API as Setter
//importing the module 'url'
const http = require('url');
// creating and intializing URLSearchParams object
const params = new URLSearchParams();
// appending value in the object
// by using append() api
params.append('A', 'Book');
params.append('B', 'Pen');
params.append('C', 'Pencile');
//display the result
console.log(params.toString());
// appending value in the object
// by using append() api
params.set('A', 'Taj');
params.set('C', 'Mahal');
// display the result
console.log("\n" +params.toString());
Output :
A=Book&B=Pen&C=Pencile A=Taj&B=Pen&C=Mahal
Example 2 :
// node program to demonstrate the
// URLSearchParams.append API as Setter
//importing the module 'url'
const http = require('url');
// creating and intializing URLSearchParams object
const params = new URLSearchParams();
// appending value in the object
// by using append() api
params.append('A', 'Book');
params.append('B', 'Pen');
params.append('C', 'Pencile');
//display the result
console.log(params.toString());
Output :
A=Book&B=Pen&C=Pencile
Note : The above program will not run on online JavaScript and script editor . Reference: https://nodejs.org/dist/latest-v14.x/docs/api/url.html#url_urlsearchparams_append_name_value