URLSearchParams

URLSearchParams.prototype.has

Returns a boolean indicating whether the specified parameter exists in the search params

Syntax

JavaScript
params.has(name, value?)

Parameters

ParameterTypeDescription
namestringThe name of the parameter to check
valuestringOptional specific value to check for

Return Value

true if the parameter exists, false otherwise

Examples

Basic Usage
const params = new URLSearchParams('q=hello&page=1')
console.log(params.has('q')) // true
console.log(params.has('sort')) // false
Practical Example
const params = new URLSearchParams('color=red&color=blue')
console.log(params.has('color', 'red')) // true
console.log(params.has('color', 'green')) // false
Advanced Usage
function 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

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.