Node | 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 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Create a test URLSearchParams object
const myURL = new URL('https://example.org/?keya=vala&keyb=valb');
  
// Log the values
myURL.searchParams.forEach(function(value, key) {
  console.log(value, key);
});

chevron_right


Output:

vala keya
valb keyb

Example2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

par parval
foo fooval
bar barval

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.