URL

URLSearchParams.set()

Replaces the values for a name with one value, adding the pair if absent. Tested on Node.js 22.16.0. Use append when multiple values should be preserved.

Formal Syntax & Structure

nodejs syntaxnodejs
params.set(name, value)

Parameters & Attributes

NameTypeDescription
namestringParameter name.
valuestringReplacement value.

Return Value

undefined

Mutates the parameter list.

Working Example

Example Snippetnodejs
import { URL, URLSearchParams, fileURLToPath, pathToFileURL } from 'node:url';const p=new URLSearchParams('page=1&page=2&sort=title');p.set('page','3');console.log(p.toString());
Node.js Reference