Open In App

Node.js URLSearchParams.has() Method

Last Updated : 14 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report
In URLSearchParams interface, the has() method returns a Boolean which tells us that if the parameter with input name exists it will return true, else false. Syntax:
var Bool = URLSearchParams.has(name)
Returns: True - if name present, else it will return False. Parameters: name - Input the name of the parameter. Example1: javascript
let url = new URL('https://example.com?par=5&bar=4');
let param = new URLSearchParams(url.search.slice(1));

param.has('bar') === true; 
Output:
true
Example2: When input parameter is not present javascript
let url = new URL('https://example.com?par=5&bar=4');
let param = new URLSearchParams(url.search.slice(1));

param.has('foo') === true; 
Output:
false
Supported Browsers:
  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari

Next Article

Similar Reads