URLSearchParams
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.
Instance Members
Append a new name-value pair to the query string.
Name | Type |
---|---|
name |
String |
value |
String |
Remove all name-value pairs whose name is name
.
Name | Type |
---|---|
name |
String |
entries(): js.node.Iterator
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
.
Returns |
---|
js.node.Iterator |
Iterates over each name-value pair in the query and invokes the given function.
Name | Type | Default |
---|---|---|
fn |
Function | |
thisArg |
Dynamic | (optional) |
Returns the value of the first name-value pair whose name is name
.
If there are no such pairs, null
is returned.
Name | Type |
---|---|
name |
String |
Returns |
---|
String |
Returns the values of all name-value pairs whose name is name
.
If there are no such pairs, an empty array is returned.
Name | Type |
---|---|
name |
String |
Returns |
---|
Array<String> |
Returns true
if there is at least one name-value pair whose name is name
.
Name | Type |
---|---|
name |
String |
Returns |
---|
Bool |
keys(): js.node.Iterator
Returns an ES6 Iterator
over the names of each name-value pair.
Returns |
---|
js.node.Iterator |
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.
Name | Type |
---|---|
name |
String |
value |
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.
Returns |
---|
String |
values(): js.node.Iterator
Returns an ES6 Iterator
over the values of each name-value pair.
Returns |
---|
js.node.Iterator |
new(): Void
Metadata
Name | Parameters |
---|---|
:jsRequire |
"url", "URLSearchParams" |