- 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.entries() Method
The NodeJS URLSearchParams.entries() method returns an ES6 Iterator allowing iteration through all the name-value pairs present in the query string.
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.entries() method
URLSearchParams.entries()
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.
The below example demonstrates the usage of the Node.js URLSearchParams.entries() method
Example
If the input URL string contains a query segment, the NodeJS urlSearchParams.entries() 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?1=One&2=Two&3=Three'); console.log("URL: ", Myurl.href); let params = new URLSearchParams('1=One&2=Two&3=Three'); 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
After executing the above program, the NodeJS entries() method returns the name-value pairs in the input query string.
URL: https://www.tutorialspoint.com/?1=One&2=Two&3=Three Query portion of the URL: 1=One&2=Two&3=Three The name/value pairs are: "1, One" "2, Two" "3, Three"
To Continue Learning Please Login
Login with Google