Horje
Node.js URLSearchParams.set()

In URLSearchParams interface, the set() method sets the value given as an input parameter.If there are several values matching the input parameter then it deletes the others and if the value does not exist then it creates it.

Syntax:

URLSearchParams.set(name, value)

Parameters:
name – Input the name of the parameter.
value – Input the value of the parameter.

Example 1:




let url = new URL('https://example.com?fo=4&bar=6');
let params = new URLSearchParams(url.search.slice(1));
  
//Add another parameter.
params.set('par', 5);
console.log(params.toString());

Output:

fo=4&bar=6&par=5

Example 2: Adding multiple parameters




let url = new URL('https://example.com?a=1&b=2');
let params = new URLSearchParams(url.search.slice(1));
  
//Add another parameter.
params.set('c', 3);
params.set('d', 4);
console.log(params.toString());

OUTPUT:

a=1&b=2&c=3&d=4

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari


Reffered: https://www.geeksforgeeks.org


Node.js

Related
Node.js URLSearchParams.toString() Node.js URLSearchParams.toString()
Node.js URL.domainToASCII Node.js URL.domainToASCII
Node.js URL.domainToUnicode Node.js URL.domainToUnicode
Node.js urlObject.port API Node.js urlObject.port API
Node.js URL.resolve(from,to) API Node.js URL.resolve(from,to) API

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9