--- title: URLSearchParams slug: Web/API/URLSearchParams translation_of: Web/API/URLSearchParams ---

{{ApiRef("URL API")}}

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

Об'єктна реалізація URLSearchParams може використовуватись напряму в {{jsxref("Statements/for...of", "for...of")}} структурі, замість {{domxref('URLSearchParams.entries()', 'entries()')}}: for (var p of mySearchParams) що еквівалентно до for (var p of mySearchParams.entries()).

Конструктор

{{domxref("URLSearchParams.URLSearchParams", 'URLSearchParams()')}}
Конструктор вертає URLSearchParams об'єкт.

Properties

This interface doesn't inherit any property.

Методи

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

{{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.toString()")}}
Returns a string containg a query string suitable for use in a URL.
{{domxref("URLSearchParams.values()")}}
Returns an {{jsxref("Iteration_protocols", "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
{{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 Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatChrome(49)}} {{CompatGeckoMobile("29.0")}} {{CompatNo}} {{CompatUnknown}} {{CompatNo}} {{CompatChrome(49)}}
entries(), keys(), values(), and support of for...of {{CompatNo}} {{CompatChrome(49)}} {{CompatGeckoMobile("44.0")}} {{CompatNo}} {{CompatUnknown}} {{CompatNo}} {{CompatChrome(49)}}

See also