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()).
URLSearchParams()URLSearchParams object.This interface doesn't inherit any properties.
This interface doesn't inherit any methods.
URLSearchParams.append()URLSearchParams.delete()URLSearchParams.entries()iterator allowing to go through all key/value pairs contained in this object.URLSearchParams.get()URLSearchParams.getAll()URLSearchParams.has()Boolean indicating if such a search parameter exists.URLSearchParams.keys()iterator allowing to go through all keys of the key/value pairs contained in this object.URLSearchParams.set()URLSearchParams.sort()URLSearchParams.toString()URLSearchParams.values()iterator allowing to go through all values of the key/value pairs contained in this object.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"
| Specification | Status | Comment |
|---|---|---|
| URL The definition of 'URLSearchParams' in that specification. | Living Standard | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 49 | 17 | 29
|
No | 36 | 10.1 |
URLSearchParams() constructor |
49 | ? | 29 | No | 36 | ? |
append |
49 | 17 | 29 | No | 36 | ? |
delete |
49 | 17 | 29 | No | 36 | ? |
entries |
49 | ? | 44 | No | 36 | ? |
get |
49 | 17 | 26 | No | 36 | ? |
getAll |
49 | 17 | 26 | No | 36 | ? |
has |
49 | 17 | 26 | No | 36 | ? |
keys |
49 | ? | 44 | No | 36 | ? |
set |
49 | 17 | 26 | No | 36 | ? |
sort |
61 | 17 | 54 | No | 48 | ? |
toString |
49 | ? | 29 | No | 36 | ? |
values |
49 | ? | 44 | No | 36 | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | 49 | 49 | 17 | 29
|
36 | No | ? |
URLSearchParams() constructor |
49 | 49 | ? | 29 | 36 | ? | ? |
append |
49 | 49 | 17 | 29 | 36 | ? | ? |
delete |
49 | 49 | 17 | 29 | 36 | ? | ? |
entries |
49 | 49 | ? | 44 | 36 | ? | ? |
get |
49 | 49 | 17 | 26 | 36 | ? | ? |
getAll |
49 | 49 | 17 | 26 | 36 | ? | ? |
has |
49 | 49 | 17 | 26 | 36 | ? | ? |
keys |
49 | 49 | ? | 44 | 36 | ? | ? |
set |
49 | 49 | 17 | 26 | 36 | ? | ? |
sort |
61 | 61 | 17 | 54 | 48 | ? | ? |
toString |
49 | 49 | ? | 29 | 36 | ? | ? |
values |
49 | 49 | ? | 44 | 36 | ? | ? |
URL, URLUtils.
© 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