Open In App

Node.js URLSearchParams.entries()

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: 






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




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

Article Tags :