

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
URLSearchParams entries & forEach in Node
Introduction to entries() −
This function returns an iterator that allows us to iterate all over the entry set that are present in the object. It basically gives us a tool to iterate over the complete entry set of the param object.
Syntax
URLSearchParams.entries();
It will return an ES6 type iterator with all the name-value pair values.
Example
// Defining the parameters as a variable var params = new URLSearchParams('key1=value1&key2=value2&key3=value3'); // Iterating over the values of params for(var entry of params.entries()) { console.log(entry[0] + ' -> ' + entry[1]); }
Output
key1 -> value1 key2 -> value2 key3 -> value3
Example
// Defining the URL as a constant const params = new URLSearchParams( 'name=John&age=21'); // Iterating over the values of params for(var entry of params.entries()) { console.log(entry[0] + ' -> ' + entry[1]); }
Output
name -> John age -> 21
Introduction to forEach(fn[,arg])
The fn described under the forEach will be invoked each and every name-value pair that will iterated through this forEach loop and arg is an object that will be used when 'fn' is called. It will be called over each name-value pair in the query and invokes the function.
Syntax
URLSearchParams.forEach();
It will return an ES6 type iterator with the name-value pair over all the keys.
Example
// Defining the URL as a constant const url = new URL( 'https://example.com/name=John&age=21'); // Iterating over the values of params url.searchParams.forEach(function(value,key) { console.log(value, key); });
Output
name John age 21
Example
// Defining the parameters as a constant const myURL = new URL( 'https://example.com/key1=value1&key2=value2&key3=value3'); // Iterating over the values of params myURL.searchParams.forEach( (value, name, searchParams) => { console.log(name, value, myURL.searchParams === searchParams); });
Output
key1 value1 true key2 value2 true key3 value3 true
- Related Questions & Answers
- URLSearchParams sort & toString() in Node
- URLSearchParams values & keys() in Node
- Foreach in C++ and C#
- Foreach in C++ and Java
- Introduction to URLSearchParams API in Node.js
- What are reversing entries and their journal entries?\n
- Difference Between For and Foreach in PHP
- foreach in Java
- How are the journal entries and legal entries recorded for contingent liabilities?
- Difference between Collection.stream().forEach() and Collection.forEach() in Java
- foreach Loop in C#
- PHP foreach Loop.
- First and last child node of a specific node in JavaScript?
- Iterator vs forEach in Java
- IntStream forEach() method in Java
Advertisements