Open In App

Node.js URLSearchParams.entries()

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

In the URLSearchParams interface, the entries() method returns an iterator that allows iterating through all the key/value pairs present in the object. The key/value is USVString objects. 

Syntax:

searchParams.entries();

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

Example 1: 

javascript




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


Output:

keya, vala
keyb, valb

Example 2: 

javascript




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


Output:

par, parval
foo, fooval
bar, barval

Supported Browsers:

  • Google Chrome
  • Firefox
  • Edge (partial)
  • Opera
  • Apple Safari

Last Updated : 31 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads