URL

URL.prototype.searchParams

Returns a URLSearchParams object allowing access to the GET query arguments contained in the URL

Syntax

JavaScript
url.searchParams

Return Value

A URLSearchParams object

Examples

Basic Usage
const url = new URL('https://example.com?q=hello&page=1')
console.log(url.searchParams.get('q')) // 'hello'
console.log(url.searchParams.get('page')) // '1'
Practical Example
const url = new URL('https://example.com/search')
url.searchParams.set('q', 'javascript')
url.searchParams.set('limit', '10')
console.log(url.href)
Advanced Usage
function getAllParams(urlStr: string): Record<string, string> {
  const params = new URL(urlStr).searchParams
  return Object.fromEntries(params.entries())
}

Understanding URL.prototype.searchParams

The URL.prototype.searchParams method in JavaScript returns a URLSearchParams object allowing access to the GET query arguments contained in the URL. It belongs to the URL object and is one of the most widely used methods for working with url values in modern JavaScript and TypeScript applications.

The method signature is url.searchParams. When called, it returns a urlsearchparams object. Understanding when and how to use searchParams() helps you write more expressive, readable code.

Common use cases for URL.prototype.searchParams 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-constructor, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for URL.prototype.searchParams 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 URL Methods

Other methods in the URL object

Related Tools

More URL Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.