W3cubDocs

/DOM

URLSearchParams.constructor

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

Syntax

var URLSearchParams = new URLSearchParams(init);

Parameters

init Optional
A 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 compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 49 ? 29 No 36 ?
USVString or sequence for init object 61 ? 53 No 48 ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 49 49 ? 29 36 ? ?
USVString or sequence for init object 61 61 ? 53 48 ? ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams