The URLSearchParams interface defines utility methods to work with the query string of a URL.

An object implementing URLSearchParams can directly be used in a for...of structure, instead of entries(): for (var p of mySearchParams) is equivalent to for (var p of mySearchParams.entries()).

Constructor

URLSearchParams()
Constructor returning a URLSearchParams object.

Properties

This interface doesn't inherit any properties.

Methods

This interface doesn't inherit any methods.

URLSearchParams.append()
Appends a specified key/value pair as a new search parameter.
URLSearchParams.delete()
Deletes the given search parameter, and its associated value, from the list of all search parameters.
URLSearchParams.entries()
Returns an iterator allowing to go through all key/value pairs contained in this object.
URLSearchParams.get()
Returns the first value associated to the given search parameter.
URLSearchParams.getAll()
Returns all the values associated with a given search parameter.
URLSearchParams.has()
Returns a Boolean indicating if such a search parameter exists.
URLSearchParams.keys()
Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
URLSearchParams.set()
Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
URLSearchParams.sort()
Sorts all key/value pairs, if any, by their keys.
URLSearchParams.toString()
Returns a string containing a query string suitable for use in a URL.
URLSearchParams.values()
Returns an iterator allowing to go through all values of the key/value pairs contained in this object.

Example

var paramsString = "q=URLUtils.searchParams&topic=api";
var searchParams = new URLSearchParams(paramsString);

//Iterate the search parameters.
for (let p of searchParams) {
  console.log(p);
}

searchParams.has("topic") === true; // true
searchParams.get("topic") === "api"; // true
searchParams.getAll("topic"); // ["api"]
searchParams.get("foo") === null; // true
searchParams.append("topic", "webdev");
searchParams.toString(); // "q=URLUtils.searchParams&topic=api&topic=webdev"
searchParams.set("topic", "More webdev");
searchParams.toString(); // "q=URLUtils.searchParams&topic=More+webdev"
searchParams.delete("topic");
searchParams.toString(); // "q=URLUtils.searchParams"

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
Basic supportChrome Full support 49Edge Full support 17Firefox Full support 29
Notes
Full support 29
Notes
Notes Prior to version 57 single quotes in URLs were escaped (see bug 1386683).
IE No support NoOpera Full support 36Safari Full support 10.1WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 29
Notes
Full support 29
Notes
Notes Prior to version 57 single quotes in URLs were escaped (see bug 1386683).
Opera Android Full support 36Safari iOS No support NoSamsung Internet Android ?
URLSearchParams() constructorChrome Full support 49Edge ? Firefox Full support 29IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android Full support 29Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
appendChrome Full support 49Edge Full support 17Firefox Full support 29IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 29Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
deleteChrome Full support 49Edge Full support 17Firefox Full support 29IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 29Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
entriesChrome Full support 49Edge ? Firefox Full support 44IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android Full support 44Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
getChrome Full support 49Edge Full support 17Firefox Full support 26IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 26Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
getAllChrome Full support 49Edge Full support 17Firefox Full support 26IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 26Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
hasChrome Full support 49Edge Full support 17Firefox Full support 26IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 26Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
keysChrome Full support 49Edge ? Firefox Full support 44IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android Full support 44Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
setChrome Full support 49Edge Full support 17Firefox Full support 26IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support 17Firefox Android Full support 26Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
sortChrome Full support 61Edge Full support 17Firefox Full support 54IE No support NoOpera Full support 48Safari ? WebView Android Full support 61Chrome Android Full support 61Edge Mobile Full support 17Firefox Android Full support 54Opera Android Full support 48Safari iOS ? Samsung Internet Android ?
toStringChrome Full support 49Edge ? Firefox Full support 29IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android Full support 29Opera Android Full support 36Safari iOS ? Samsung Internet Android ?
valuesChrome Full support 49Edge ? Firefox Full support 44IE No support NoOpera Full support 36Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android Full support 44Opera Android Full support 36Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Last updated by: fscholz,