- 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.values() Method
The NodeJS urlSearchParams.values() method of class URLSearchParams returns an ES6 iterator that allows iteration through all the values of each name-value pair.
Let’s consider a YouTube URL (‘https://www.youtube.com/watch?z=HY4&z=NJ7), where the portion after the ‘?’ is known as the query segment. In this query, (z) is the name, and (HY4) is the value. Together it forms a name-value pair.
There are two name-value pairs in the query string. So if we assign the query string to the values() method, it returns an ES6 iterator over the values of each name-value pair.
The URLSearchParams API provides methods that give access to read and write the query of a URL. This class is also available on the global object.
Syntax
Following is the syntax of the NodeJS URLSearchParams.values() method
URLSearchParams.values()
Parameters
This method does not accept any parameters.
Return Value
This method returns an ES6 iterator over the values of each name-value pair.
The following examples demonstrate the usage of the NodeJS URLSearchParams.values() method:
Example
If the input URL string contains a query segment, the NodeJS urlSearchParams.values() method returns an iterator over all the values of name-value pairs from the query string.
In the following example, we are trying to get all the values from the name-value pairs of the query string.
const url = require('node:url'); const MyUrl = new URL('https://www.tutorialspoint.com?1=one&3=three&6=six&9=nine'); console.log("URL: ", MyUrl.href); const Params = new URLSearchParams('1=one&3=three&6=six&9=nine'); console.log("Query string: " + Params); console.log('All the values in the query string are: '); for (const value of Params.values()) { console.log(value); }
Output
As we can see in the below output, the NodeJS values() method returns all the values from the name-value pairs.
URL: https://www.tutorialspoint.com/?1=one&3=three&6=six&9=nine Query string: 1=one&3=three&6=six&9=nine All the values in the query string are: one three six nine
Example
In the following example, we are appending some name-value pairs to the input query string. Then we are trying to get the values from the name-value pairs.
const url = require('node:url'); const Params = new URLSearchParams('1=one&3=three&6=six&9=nine'); console.log("Query string: " + Params); Params.append(12, 'twelve'); Params.append(15, 'fifteen'); console.log('All the values in the query string are: '); for (const value of Params.values()) { console.log(value); }
Output
On executing the above program, it will generate the following output
Query string: 1=one&3=three&6=six&9=nine All the values in the query string are: one three six nine twelve fifteen
To Continue Learning Please Login
Login with Google