URLSearchParams
Creates a new URLSearchParams object from a query string, entries, or record
Syntax
new URLSearchParams(init?)Parameters
| Parameter | Type | Description |
|---|---|---|
| init | string | Record<string, string> | [string, string][] | URLSearchParams | Initial data for the params |
Return Value
A new URLSearchParams object
Examples
const params = new URLSearchParams('q=hello&page=1')
console.log(params.get('q')) // 'hello'const params = new URLSearchParams({
search: 'javascript',
sort: 'relevance',
page: '1'
})
console.log(params.toString())const params = new URLSearchParams([
['color', 'red'],
['color', 'blue'],
['size', 'large']
])
console.log(params.getAll('color')) // ['red', 'blue']Understanding URLSearchParams
The URLSearchParams method in JavaScript creates a new URLSearchParams object from a query string, entries, or record. 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 new URLSearchParams(init?). It accepts 1 parameter: init. When called, it returns a new urlsearchparams object. Understanding when and how to use URLSearchParams() helps you write more expressive, readable code.
Common use cases for URLSearchParams 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-append, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for URLSearchParams 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.appendAppends a specified key/value pair as a new search parameter, without removing existing ones with the same name
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.