Open In App

Node.js URLSearchParams.keys()

In URLSearchParams interface, the keys() method returns an Iterator which allows us to iterate through all the keys present in the object.

Syntax:



searchParams.keys();

Return:Returns an ES6 Iterator over the names of each name-value pair.

Example 1:






var searchParams = new URLSearchParams("keyA=valueA&keyB=valueB"); 
  
// Display the key/value pairs 
for(var key of searchParams.keys()) { 
  console.log(key); 
}

Output:

keyA
keyB

Example2:




var searchParams = new URLSearchParams("name=john&age=18"); 
  
// Display the key/value pairs 
for(var key of searchParams.keys()) { 
  console.log(key); 
}

Output:

name
age

Supported Browsers:

Article Tags :