The URLSearchParams API provides read and write access to the query of a URL. The URLSearchParams class can also be used standalone with one of the four following constructors. The URLSearchParams class is also available on the global object.

The WHATWG URLSearchParams interface and the querystring module have similar purpose, but the purpose of the querystring module is more general, as it allows the customization of delimiter characters (& and =`). On the other hand, this API is designed purely for URL query strings.

Constructor

Methods

append(name:String, value:String):Void

Append a new name-value pair to the query string.

delete(name:String):Void

Remove all name-value pairs whose name is name.

entries():Iterator<URLSearchParamsEntry>

Returns an ES6 Iterator over each of the name-value pairs in the query. Each item of the iterator is a JavaScript Array. The first item of the Array is the name, the second item of the Array is the value.

forEach(fn:(value:String, name:String, searchParams:URLSearchParams) ‑> Void, ?thisArg:Dynamic):Void

forEach(fn:(value:String) ‑> Void, ?thisArg:Dynamic):Void

forEach(fn:(value:String, name:String) ‑> Void, ?thisArg:Dynamic):Void

Iterates over each name-value pair in the query and invokes the given function.

get(name:String):String

Returns the value of the first name-value pair whose name is name. If there are no such pairs, null is returned.

getAll(name:String):Array<String>

Returns the values of all name-value pairs whose name is name. If there are no such pairs, an empty array is returned.

has(name:String):Bool

Returns true if there is at least one name-value pair whose name is name.

keys():Iterator<String>

Returns an ES6 Iterator over the names of each name-value pair.

set(name:String, value:String):Void

Sets the value in the URLSearchParams object associated with name to value. If there are any pre-existing name-value pairs whose names are name, set the first such pair's value to value and remove all others. If not, append the name-value pair to the query string.

sort():Void

Sort all existing name-value pairs in-place by their names. Sorting is done with a stable sorting algorithm, so relative order between name-value pairs with the same name is preserved.

This method can be used, in particular, to increase cache hits.

toString():String

Returns the search parameters serialized as a string, with characters percent-encoded where necessary.

values():Iterator<String>

Returns an ES6 Iterator over the values of each name-value pair.