Node.js urlSearchParams.get() Method
Last Updated :
07 Oct, 2021
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
const http = require( 'url' );
const params = new URLSearchParams();
params.append( 'A' , 'Book' );
params.append( 'B' , 'Pen' );
params.append( 'C' , 'Pencile' );
const value = params.get( 'A' );
console.log( "value for A is " + value);
|
Run app.js file using the following command:
node app.js
Output:
value for A is Book
Example 2: Filename: app.js
const http = require( 'url' );
const params = new URLSearchParams();
params.append( 'A' , 'Book' );
params.append( 'B' , 'Pen' );
params.append( 'C' , 'Pencile' );
const value = params.get( 'a' );
console.log( "value for a is " + value);
|
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
Share your thoughts in the comments
Please Login to comment...