URLSearchParams()

The URLSearchParams() constructor creates and returns a new URLSearchParams object. Leading '?' characters are ignored.

Note: This feature is available in Web Workers.

Syntax

var URLSearchParams = new URLSearchParams(init);

Parameters

init Optional
USVString instance, a URLSearchParams instance, a sequence of USVStrings, or a record containing USVStrings. Note that using a URLSearchParams instance is deprecated; soon browsers will just use a USVString for the init.

Return value

An instance of URLSearchParams.

Examples

The following example shows how to create a URLSearchParams object from a URL string.

// Pass in a string literal
var url = new URL('https://example.com?foo=1&bar=2');
// Retrieve from window.location
var url2 = new URL(window.location);

// Retrieve params via url.search, passed into ctor
var params = new URLSearchParams(url.search);
var params2 = new URLSearchParams(url2.search);

// Pass in a sequence
var params3 = new URLSearchParams([["foo", 1],["bar", 2]]);

// Pass in a record
var params4 = new URLSearchParams({"foo" : 1 , "bar" : 2});

Specifications

Specification Status Comment
URL
The definition of 'URLSearchParams()' in that specification.
Living Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
URLSearchParams() constructorChrome Full support 49Edge Full support 17Firefox Full support 29IE No support NoOpera Full support 36Safari Full support YesWebView Android Full support 49Chrome Android Full support 49Edge Mobile No support NoFirefox Android Full support 29Opera Android Full support 36Safari iOS Full support YesSamsung Internet Android Full support Yes
USVString or sequence for init objectChrome Full support 61Edge Full support 17Firefox Full support 53IE No support NoOpera Full support 48Safari Full support YesWebView Android Full support 61Chrome Android Full support 61Edge Mobile No support NoFirefox Android Full support 53Opera Android Full support 45Safari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support

Document Tags and Contributors

Last updated by: mdnwebdocs-bot,