Skip to content
Related Articles

Related Articles

Improve Article

Node.js URLSearchParams.forEach()

  • Last Updated : 14 Oct, 2021

In URLSearchParams interface, the foreach() method returns an iterator which allows to iterate through all values contained in this object with the help of a callback function.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

searchParams.forEach(callback);

Return: It does not return anything, used for invoking the function and iteraating through it.

Parameters:
callback – Input the callback function that wil be executed against each parameter, with the value of the parameter provided as its parameter.



Example1:




// Create a test URLSearchParams object
  
// Log the values
myURL.searchParams.forEach(function(value, key) {
  console.log(value, key);
});

Output:

vala keya
valb keyb

Example2:




// Create a test URLSearchParams object
  
// Log the values
myURL.searchParams.forEach(function(value, key) {
  console.log(key,value);
});

Output:

par parval
foo fooval
bar barval

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari
My Personal Notes arrow_drop_up
Recommended Articles
Page :