URLSearchParams інтерфейс визначає корисні методи для роботи з довгими текстовими URL.

Об'єктна реалізація URLSearchParams може використовуватись напряму в for...of структурі, замість entries() (en-US): for (var p of mySearchParams) що еквівалентно до for (var p of mySearchParams.entries()).


URLSearchParams() (en-US)
Конструктор вертає URLSearchParams об'єкт.


This interface doesn't inherit any property.


Інтерфейс на наслідує ніяких методів

URLSearchParams.append() (en-US)
Appends a specified key/value pair as a new search parameter.
URLSearchParams.delete() (en-US)
Deletes the given search parameter, and its associated value, from the list of all search parameters.
URLSearchParams.entries() (en-US)
Returns an iterator allowing to go through all key/value pairs contained in this object.
URLSearchParams.get() (en-US)
Returns the first value associated to the given search parameter.
URLSearchParams.getAll() (en-US)
Returns all the values association with a given search parameter.
URLSearchParams.has() (en-US)
Returns a Boolean indicating if such a search parameter exists.
URLSearchParams.keys() (en-US)
Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
URLSearchParams.set() (en-US)
Sets the value associated to a given search parameter to the given value. If there were several values, delete the others.
URLSearchParams.toString() (en-US)
Returns a string containg a query string suitable for use in a URL.
URLSearchParams.values() (en-US)
Returns an 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) {

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.toString(); // "q=URLUtils.searchParams"


Specification Status Comment
The definition of 'URLSearchParams' in that specification.
Living Standard Initial definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 49 29.0 (29.0) No support 36 No support
entries(), keys(), values(), and support of for...of 49 44.0 (44.0) No support 36 No support
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 49 29.0 (29.0) No support ? No support 49
entries(), keys(), values(), and support of for...of No support 49 44.0 (44.0) No support ? No support 49

See also