Node.js URLSearchParams.get()
Last Updated :
14 Oct, 2021
Improve
In URLSearchParams interface, the get() method returns the first value of the input search parameter.
Syntax:
javascript
Output:
javascript
Output:
URLSearchParams.get(name)Returns:The string will be returned if the name-value pair is found, else null will be returned. Parameters: name - Input the name of the parameter. Example1: When input parameter is present
var URL = require('url').URL;
let url = new URL('https://example.com/?name=Deepak&age=20');
let params = new URLSearchParams(url.search.substring(1));
let name = params.get("name"); // is the string "Deepak"
let age = parseInt(params.get("age"), 10); // is the number 20
console.log(name)
console.log(age)
Deepak 20Example2: When input parameter is not present
var URL = require('url').URL;
let url = new URL('https://example.com/?name=Deepak&age=20');
let params = new URLSearchParams(url.search.substring(1));
let address = params.get("address");
console.log(address)
nullSupported Browsers:
- Google Chrome
- IE
- Edge
- Opera
- Apple Safari