- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
NodeJS urlSearchParams[Symbol.iterator]() Method
The NodeJS URLSearchParams[Symbol.iterator]() method returns an ES6 Iterator allowing iteration through all the name-value pairs present in the query string. This method is an alias for URLSearchParams.entries() method.
The iterator returns the name-value pairs in the same order as they present in the query string. Each returned item of the iterator is a JavaScript array. The first item present in the array is the name and the second item is the value, together forming a name-value pair.
The URLSearchParams API provides read and write access to the query of a URL. This class is also available on the global object.
Syntax
Following is the syntax of the NodeJS URLSearchParams[Symbol.iterator]() method
URLSearchParams[Symbol.iterator]()
Parameters
This method does not accept any parameters.
Return Value
This method returns an ES6 iterator over each of the name-value pairs in the query string.
Example
If the input URL string contains a query segment, the NodeJS URLSearchParams[Symbol.iterator]() method will return an iterator over each of the name-value pairs from the query string.
In the following example, we are trying to get the name-value pairs from the input query string.
const url = require('node:url'); let Myurl = new URL('https://www.tutorialspoint.com?10=Ten&20=Twenty&30=Thirty&40=Fourty'); console.log("URL: ", Myurl.href); let params = new URLSearchParams('10=Ten&20=Twenty&30=Thirty&40=Fourty'); console.log("Query portion of the URL: " + params.toString()); console.log("The name/value pairs are: ") for (const [key, value] of params.entries()) { console.log(JSON.stringify(`${key}, ${value}`)); }
Output
On executing the above program, it will generate the following output
URL: https://www.tutorialspoint.com/?10=Ten&20=Twenty&30=Thirty&40=Fourty Query portion of the URL: 10=Ten&20=Twenty&30=Thirty&40=Fourty The name/value pairs are: "10, Ten" "20, Twenty" "30, Thirty" "40, Fourty"
To Continue Learning Please Login
Login with Google