Web APIs
URLSearchParams.set()
Replaces the first matching pair and removes other matches, or appends a new pair if absent.
Formal Syntax & Structure
javascript syntaxjavascript
params.set(name, value)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Parameter name. |
| value | string | New value. |
Return Value
undefined
No return value.
Working Example
Example Snippetjavascript
(async () => {const u=new URL("https://example.test/?q=old&q=other");u.searchParams.set("q","a+b c");console.log(u.searchParams.toString(),u.search);})()