= URLSearchParams
{c}
<URLSearchParams> is an <API> for representing and manipulating an ordered list of name/value pairs, commonly obtained from a <URL>'s <query string>. Repeated names are permitted. It uses <form URL encoding>, rather than imposing its interpretation on every conceivable query syntax.<URL API in the Node.js documentation>[Class URLSearchParams, constructors and iteration]{ref}
For `new URLSearchParams('tag=a&tag=b&q=a+b')`, `getAll('tag')` returns both `a` and `b`, while `get('q')` returns `a b`. Calling `set('tag','c')` replaces the repeated entries with one: `toString()` then returns `tag=c&q=a+b`. An <associative array> holding just one value for each name would discard the original repeated-field information.
A literal plus needs a different spelling. Appending the pair `q` and `a+b` to a <URL>'s `searchParams` produces query `?q=a%2Bb`. The plus in the data is represented by <percent-encoding>, whereas the plus in `q=a+b` represents a space under this parser. These examples distinguish a character in a value from a character used by the encoding convention.<URL API in the Node.js documentation>[URLSearchParams.getAll, set, append and toString]{ref}
A <URL>'s `searchParams` object is connected to that <URL>; changes update its query. Constructing a separate <URLSearchParams> from a query string instead gives an independent object, useful when the original spelling must remain available for comparison.<URL Standard by WHATWG>[Section6.2, URL object association and update steps]{ref}
Back to article page