URLSearchParams.prototype.has
Returns a boolean indicating whether the specified parameter exists in the search params
Syntax
params.has(name, value?)Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | The name of the parameter to check |
| value | string | Optional specific value to check for |
Return Value
true if the parameter exists, false otherwise
Examples
const params = new URLSearchParams('q=hello&page=1')
console.log(params.has('q')) // true
console.log(params.has('sort')) // falseconst params = new URLSearchParams('color=red&color=blue')
console.log(params.has('color', 'red')) // true
console.log(params.has('color', 'green')) // falsefunction requireParams(params: URLSearchParams, required: string[]) {
const missing = required.filter(r => !params.has(r))
if (missing.length) throw new Error(`Missing: ${missing.join(', ')}`)
}Understanding URLSearchParams.prototype.has
The URLSearchParams.prototype.has method in JavaScript returns a boolean indicating whether the specified parameter exists in the search params. It belongs to the URLSearchParams object and is one of the most widely used methods for working with urlsearchparams values in modern JavaScript and TypeScript applications.
The method signature is params.has(name, value?). It accepts 2 parameters: name, value. When called, it returns true if the parameter exists, false otherwise. Understanding when and how to use has() helps you write more expressive, readable code.
Common use cases for URLSearchParams.prototype.has include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like urlsearchparams-get, urlsearchparams-set, urlsearchparams-delete, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for URLSearchParams.prototype.has is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
URLSearchParams.prototype.getReturns the first value associated to the given search parameter
URLSearchParams.prototype.setSets the value associated to a given search parameter to the given value, removing others with the same name
URLSearchParams.prototype.deleteRemoves the given search parameter and all its associated values
More URLSearchParams Methods
Other methods in the URLSearchParams object
Related Tools
More URLSearchParams Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.