The URLSearchParams() constructor creates and returns a new URLSearchParams object.


This feature is available in Web Workers.


var URLSearchParams = new URLSearchParams(init);


init Optional

One of:

  • USVString, which will be parsed from application/x-www-form-urlencoded format. A leading '?' character is ignored.
  • A sequence of USVString pairs, representing names/values.
  • A record of USVString keys and USVString values.

Return value

A URLSearchParams object instance.


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"});


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

Browser compatibility

BCD tables only load in the browser