Skip to content
Related Articles

Related Articles

Node.js URLSearchParams.entries()

View Discussion
Improve Article
Save Article
  • Last Updated : 14 Oct, 2021
View Discussion
Improve Article
Save Article

In URLSearchParams interface, the entries() method returns an iterator which allows to iterate through all the key/value pairs present in the object.The key/value are USVString objects.

Syntax:

searchParams.entries();

Return:iterator, iterating over all key-value pairs.

Example 1:




// Create a test URLSearchParams object
var searchpar = new URLSearchParams("keya=vala&keyb=valb");
  
// Display the key/value pairs
for(var pair of searchpar.entries()) {
   console.log(pair[0]+ ', '+ pair[1]); 
}


Output:

keya, vala
keyb, valb

Example 2:




// Create a test URLSearchParams object
var searchpar = new URLSearchParams("par=parval&foo=fooval&bar=barval");
  
// Display the key/value pairs
for(var pair of searchpar.entries()) {
   console.log(pair[0]+ ', '+ pair[1]); 
}


Output:

par, parval
foo, fooval
bar, barval

Supported Browsers:

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

Start Your Coding Journey Now!