The URLSearchParams()
constructor creates and returns a new URLSearchParams
object.
Note: This feature is available in Web Workers.
Syntax
var URLSearchParams = new URLSearchParams(init);
Parameters
init
Optional
One of:
- A
USVString
, which will be parsed fromapplication/x-www-form-urlencoded
format. A leading'?'
character is ignored. - A sequence of
USVString
pairs, representing names/values. - A record of
USVString
keys andUSVString
values.
Return value
A URLSearchParams
object instance.
Examples
The following example shows how to create a URLSearchParams
object from a URL string.
// Retrieve params via url.search, passed into ctor
var url = new URL('https://example.com?foo=1&bar=2');
var params = new URLSearchParams(url.search);
// Pass in a string literal
var params2 = new URLSearchParams("foo=1&bar=2");
var params2a = new URLSearchParams("?foo=1&bar=2");
// Pass in a sequence of pairs
var params3 = new URLSearchParams([["foo", "1"], ["bar", "2"]]);
// Pass in a record
var params4 = new URLSearchParams({"foo": "1", "bar": "2"});
Specifications
Specification | Status | Comment |
---|---|---|
URLThe definition of 'URLSearchParams()' in that specification. | Living Standard | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
URLSearchParams() constructor
|
Chrome
Full support 49 |
Edge
Full support 17 |
Firefox
Full support 29 |
IE
No support No |
Opera
Full support 36 |
Safari
Full support 10.1 |
WebView Android
Full support 49 |
Chrome Android
Full support 49 |
Firefox Android
Full support 29 |
Opera Android
Full support 36 |
Safari iOS
Full support 10.3 |
Samsung Internet Android
Full support 5.0 |
USVString or sequence for init object
|
Chrome
Full support 61 |
Edge
Full support 17 |
Firefox
Full support 53 |
IE
No support No |
Opera
Full support 48 |
Safari
Full support Yes |
WebView Android
Full support 61 |
Chrome Android
Full support 61 |
Firefox Android
Full support 53 |
Opera Android
Full support 45 |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 8.0 |
Legend
- Full support
- Full support
- No support
- No support
URLSearchParams() by Mozilla Contributors is licensed under CC-BY-SA 2.5.