Node | URLSearchParams.toString()
In URLSearchParams interface, the toString() method returns a query string which is suitable for use in a URL.
Syntax:
URLSearchParams.toString()
Return:Returns the search parameters serialized as a string(with Characters percent-encoded).
Example 1:
let params = new URLSearchParams(url.search.slice(1)); //Add another parameter. params.append('par', 4); console.log(params.toString()); |
chevron_right
filter_none
Output:
'foo=1&bar=2&par=4'
Example 2: To create parameters directly
// note: params can also be directly created let params1 = url.searchParams; console.log(params1.toString()); // or even simpler let params2 = new URLSearchParams('par=1&bar;=2'); console.log(params2.toString()); |
chevron_right
filter_none
Output:
par=1&bar=2 par=1&bar=2
Supported Browsers:
- Google Chrome
- IE
- Edge
- Opera
- Apple Safari
Recommended Posts:
- Node js | OS
- Why Node.js ?
- Node | URLSearchParams.get()
- Node | URL.domainToUnicode
- Node | URL.hash API
- Node | URL.domainToASCII
- Node | URL.resolve(from,to) API
- Node | URL.host API
- Node.js | pop() function
- Routing in Node.js
- Node | URL.pathname API
- Node | URL.format API
- Node | URL.href API
- Node | URL.password API
- Node | URL.username 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.


