Skip to main content
URLSearchParams.prototype.set - node__url.d.ts - Node documentation
method URLSearchParams.prototype.set

Usage in Deno

```typescript import { URLSearchParams } from "node:node__url.d.ts"; ```
URLSearchParams.prototype.set(
name: string,
value: string,
): void
Sets the value in the `URLSearchParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`, set the first such pair's value to `value` and remove all others. If not, append the name-value pair to the query string. ```js const params = new URLSearchParams(); params.append('foo', 'bar'); params.append('foo', 'baz'); params.append('abc', 'def'); console.log(params.toString()); // Prints foo=bar&foo=baz&abc=def params.set('foo', 'def'); params.set('xyz', 'opq'); console.log(params.toString()); // Prints foo=def&abc=def&xyz=opq ```

Parameters

name: string
value: string

Return Type

void