URLSearchParams()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

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

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.

Example

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

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 49.0 29.0 (29.0) No support ? ?
USVString or sequence for init object (Yes) 53 (53) No support ? ?
Record for init object No support 54 (54) No support ? ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 49.0 29.0 (29.0) No support ? ? 49.0
USVString  of sequence for init object No support (Yes) 53.0 (53) No support ? ? (Yes)
Record for init object No support (Yes) 54.0 (54) No support ? ? (Yes)

Document Tags and Contributors

 Contributors to this page: NoInkling, TristanBerger, chrisdavidmills, msiadak, teoli, jpmedley, rolfedh
 Last updated by: NoInkling,