CKTIS / JavaScript
URLSearchParams.set(): setting a query parameter
URLSearchParams.set() assigns one parameter value, removing duplicates or appending a missing name.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
params.set(name, value)params.set(name, value) mutates the object and returns undefined, so calls cannot be chained. Both arguments are required and converted to strings.
It replaces the first matching entry's value, preserving its position, and removes other entries with that name. A missing name is appended. In contrast, append() preserves duplicates.
Pass unencoded text. Serialization turns spaces into + and literal + into %2B. Calling url.searchParams.set() updates the associated URL object.
This Web API belongs to the WHATWG URL Standard, not a particular ECMAScript edition. Check availability in the target environment; Node 24 does not establish browser support.
Examples
const params = new URLSearchParams('q=old&page=1&q=extra');
const result = params.set('q', 'a+b c');
params.set('lang', 'pl');
console.log(params.toString());
console.log(result === undefined);Result
q=a%2Bb+c&page=1&lang=pl true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.