URLSearchParams

class URLSearchParams {
constructor(init?:
| string[][]
| Record<string, string>
| string
);
append(name: string, value: string): void;
delete(name: string): void;
entries(): IterableIterator<[string, string]>;
forEach(callbackfn: (
value: string,
key: string,
parent: this,
) => void
, thisArg?: any): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
keys(): IterableIterator<string>;
set(name: string, value: string): void;
sort(): void;
toString(): string;
values(): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<[string, string]>;
 
static toString(): string;
}

§Constructors

§
new URLSearchParams(init?: string[][] | Record<string, string> | string | URLSearchParams)
[src]

§Methods

§
append(name: string, value: string): void
[src]

Appends a specified key/value pair as a new search parameter.

let searchParams = new URLSearchParams();
searchParams.append('name', 'first');
searchParams.append('name', 'second');
§
delete(name: string): void
[src]

Deletes the given search parameter and its associated value, from the list of all search parameters.

let searchParams = new URLSearchParams([['name', 'value']]);
searchParams.delete('name');
§
entries(): IterableIterator<[string, string]>
[src]

Returns an iterator allowing to go through all key/value pairs contained in this object.

const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
for (const [key, value] of params.entries()) {
  console.log(key, value);
}
§
forEach(callbackfn: (value: string, key: string, parent: this) => void, thisArg?: any): void
[src]

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.

const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
params.forEach((value, key, parent) => {
  console.log(value, key, parent);
});
§
get(name: string): string | null
[src]

Returns the first value associated to the given search parameter.

searchParams.get('name');
§
getAll(name: string): string[]
[src]

Returns all the values associated with a given search parameter as an array.

searchParams.getAll('name');
§
has(name: string): boolean
[src]

Returns a Boolean that indicates whether a parameter with the specified name exists.

searchParams.has('name');
§
keys(): IterableIterator<string>
[src]

Returns an iterator allowing to go through all keys contained in this object.

const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
for (const key of params.keys()) {
  console.log(key);
}
§
set(name: string, value: string): void
[src]

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.

searchParams.set('name', 'value');
§
sort(): void
[src]

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.

searchParams.sort();
§
toString(): string
[src]

Returns a query string suitable for use in a URL.

searchParams.toString();
§
values(): IterableIterator<string>
[src]

Returns an iterator allowing to go through all values contained in this object.

const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
for (const value of params.values()) {
  console.log(value);
}
§
[Symbol.iterator](): IterableIterator<[string, string]>
[src]

Returns an iterator allowing to go through all key/value pairs contained in this object.

const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
for (const [key, value] of params) {
  console.log(key, value);
}

§Static Methods

§
toString(): string
[src]