URLSearchParams stores an ordered list of string pairs.
new URLSearchParams("?a=1&b=2");
new URLSearchParams([["a", "1"], ["b", "2"]]);
new URLSearchParams({ a: "1", b: "2" });| Method | Purpose |
|---|---|
append(name, value) | Add a pair. |
delete(name, value?) | Remove matching pairs. |
get(name) / getAll(name) | Read the first or all values. |
has(name, value?) | Test for a pair. |
set(name, value) | Replace the first value and remove duplicates, or append. |
sort() | Stable sort by name. |
toString() | Form-encode the pair list. |
size, entries(), keys(), values(), forEach(), and the
default iterator are available. Iterators are live: later mutations affect
subsequent steps.
const params = new URLSearchParams();
params.append("k", "hello world");
params.append("unicode", "тест");
params.toString();
// "k=hello+world&unicode=%D1%82%D0%B5%D1%81%D1%82"Encoding uses UTF-8 percent escapes and + for space. A
URL object’s searchParams is live in both directions.