{{ApiRef("URL API")}}
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 {{jsxref("Statements/for...of", "for...of")}} structure, instead of {{domxref('URLSearchParams.entries()', 'entries()')}}: for (var p of mySearchParams)
is equivalent to for (var p of mySearchParams.entries())
.
Constructor
- {{domxref("URLSearchParams.URLSearchParams", 'URLSearchParams.URLSearchParams()')}}
- Constructor returning a
URLSearchParams
object.
Properties
This interface doesn't inherit any property.
Methods
This interface doesn't inherit any method.
- {{domxref("URLSearchParams.append()")}}
- Appends a specified key/value pair as a new search parameter.
- {{domxref("URLSearchParams.delete()")}}
- Deletes the given search parameter, and its associated value, from the list of all search parameters.
- {{domxref("URLSearchParams.entries()")}}
- Returns an {{jsxref("Iteration_protocols","iterator")}} allowing to go through all key/value pairs contained in this object.
- {{domxref("URLSearchParams.get()")}}
- Returns the first value associated to the given search parameter.
- {{domxref("URLSearchParams.getAll()")}}
- Returns all the values association with a given search parameter.
- {{domxref("URLSearchParams.has()")}}
- Returns a {{jsxref("Boolean")}} indicating if such a search parameter exists.
- {{domxref("URLSearchParams.keys()")}}
- Returns an {{jsxref("Iteration_protocols", "iterator")}} allowing to go through all keys of the key/value pairs contained in this object.
- {{domxref("URLSearchParams.set()")}}
- Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
- {{domxref("URLSearchParams.values()")}}
- Returns an {{jsxref("Iteration_protocols", "iterator")}} allowing to go through all values of the key/value pairs contained in this object.
Examples
var paramsString = "q=URLUtils.searchParams&topic=api" var searchParams = new URLSearchParams(paramsString); 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.delete("topic"); searchParams.toString(); // "q=URLUtils.searchParams"
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('URL', '#urlsearchparams', "URLSearchParams")}} | {{Spec2('URL')}} | Initial definition. |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatChrome(49)}} | {{CompatGeckoDesktop("29.0")}} | {{CompatNo}} | 36 | {{CompatNo}} |
entries() , keys() , values() , and support of for...of |
{{CompatChrome(49)}} | {{CompatGeckoDesktop("44.0")}} | {{CompatNo}} | 36 | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatChrome(49)}} | {{CompatGeckoMobile("29.0")}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatNo}} |
entries() , keys() , values() , and support of for...of |
{{CompatNo}} | {{CompatChrome(49)}} | {{CompatGeckoMobile("44.0")}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatNo}} |
See also
- Other URL-related interfaces: {{domxref("URL")}}, {{domxref("URLUtils")}}.
- Google Developers: Easy URL manipulation with URLSearchParams