Node urlSearchParams.get() Method

The urlSearchParams.get() method is an inbuilt application programming interface of class URLSearchParams within url module which is used to get the value for particular name entry present in the URL search params object.

Syntax:

const urlSearchParams.get( name )

Parameter: This method takes the name as a parameter.

Return value: This method returns the value for particular name entry present in the url search params object.

Below programs illustrates the use of urlSearchParams.get() method in Node.js:



Example 1: Filename: app.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the 
// URLSearchParams.get() method
   
// Importing the module 'url'
const http = require('url');
  
// Creating and initializing 
// URLSearchParams object
const params = new URLSearchParams();
  
// Appending value in the object
params.append('A', 'Book');
params.append('B', 'Pen');
params.append('C', 'Pencile');
  
// Getting the value for entry 'A'
// by using get() api
const value = params.get('A');
  
// Display the result
console.log("value for A is " + value);

chevron_right


Run app.js file using the following command:

node app.js

Output:

value for A is Book

Example 2: Filename: app.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the 
// URLSearchParams.get() method 
   
// Importing the module 'url'
const http = require('url');
  
// Creating and initializing
// URLSearchParams object
const params = new URLSearchParams();
  
// Appending value in the object
params.append('A', 'Book');
params.append('B', 'Pen');
params.append('C', 'Pencile');
  
// Getting the value for entry 'A'
// by using get() api
const value = params.get('a');
  
// Display the result
console.log("value for a is " + value);

chevron_right


Run app.js file using the following command:

node app.js

Output:

value for a is null

Reference: https://nodejs.org/dist/latest-v14.x/docs/api/url.html#url_urlsearchparams_get_name




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.