Web APIs

URLSearchParams.set()

Try the free JavaScript compiler

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

NameTypeDescription
namestringParameter name.
valuestringNew 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);})()
JavaScript Reference