Saturday, October 25, 2025
HomeLanguagesJavascriptNode.js URLSearchParams.forEach()

Node.js URLSearchParams.forEach()

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:

searchParams.forEach(callback);

Return: It does not return anything, used for invoking the function and iterating through it. Parameters: callback – Input the callback function that will be executed against each parameter, with the value of the parameter provided as its parameter. Example1: 

javascript




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


Output:

vala keya
valb keyb

Example2: 

javascript




// 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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS