Skip to main content
URLSearchParams - URL - Web documentation
interface URLSearchParams
Private

Properties

size: number
Contains the number of search parameters ```ts searchParams.size ```

Methods

append(
name: string,
value: string,
): void
Appends a specified key/value pair as a new search parameter. ```ts let searchParams = new URLSearchParams(); searchParams.append('name', 'first'); searchParams.append('name', 'second'); ```
delete(
name: string,
value?: string,
): void
Deletes search parameters that match a name, and optional value, from the list of all search parameters. ```ts let searchParams = new URLSearchParams([['name', 'value']]); searchParams.delete('name'); searchParams.delete('name', 'value'); ```
getAll(name: string): string[]
Returns all the values associated with a given search parameter as an array. ```ts searchParams.getAll('name'); ```
get(name: string): string | null
Returns the first value associated to the given search parameter. ```ts searchParams.get('name'); ```
has(
name: string,
value?: string,
): boolean
Returns a boolean value indicating if a given parameter, or parameter and value pair, exists. ```ts searchParams.has('name'); searchParams.has('name', 'value'); ```
set(
name: string,
value: string,
): void
Sets the value associated with a given search parameter to the given value. If there were several matching values, this method deletes the others. If the search parameter doesn't exist, this method creates it. ```ts searchParams.set('name', 'value'); ```
sort(): void
Sort all key/value pairs contained in this object in place and return undefined. The sort order is according to Unicode code points of the keys. ```ts searchParams.sort(); ```
forEach(
callbackfn: (
value: string,
key: string,
parent: this,
) => void
,
thisArg?: any,
): void
Calls a function for each element contained in this object in place and return undefined. Optionally accepts an object to use as this when executing callback as second argument. ```ts const params = new URLSearchParams([["a", "b"], ["c", "d"]]); params.forEach((value, key, parent) => { console.log(value, key, parent); }); ```
keys(): IterableIterator<string>
Returns an iterator allowing to go through all keys contained in this object. ```ts const params = new URLSearchParams([["a", "b"], ["c", "d"]]); for (const key of params.keys()) { console.log(key); } ```
values(): IterableIterator<string>
Returns an iterator allowing to go through all values contained in this object. ```ts const params = new URLSearchParams([["a", "b"], ["c", "d"]]); for (const value of params.values()) { console.log(value); } ```
entries(): IterableIterator<[string, string]>
Returns an iterator allowing to go through all key/value pairs contained in this object. ```ts const params = new URLSearchParams([["a", "b"], ["c", "d"]]); for (const [key, value] of params.entries()) { console.log(key, value); } ```
[[Symbol.iterator]](): IterableIterator<[string, string]>
Returns an iterator allowing to go through all key/value pairs contained in this object. ```ts const params = new URLSearchParams([["a", "b"], ["c", "d"]]); for (const [key, value] of params) { console.log(key, value); } ```
toString(): string
Returns a query string suitable for use in a URL. ```ts searchParams.toString(); ```