Node | 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 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 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
Recommended Posts:
- Why Node.js ?
- Node js | OS
- Node | URL.hash API
- Node | URLSearchParams.get()
- Node | URL.resolve(from,to) API
- Node | URL.domainToASCII
- Routing in Node.js
- Node | URL.pathToFileURL API
- Node | URL.fileURLToPath API
- Node | URL.protocol API
- Node | URLSearchParams.has()
- Node | URL.password API
- HTTPS in Node
- Node | URL.hostname API
- Node | URL.href API
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



