Skip to content
Related Articles

Related Articles

Node.js URLSearchParams.keys()

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

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:

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

Start Your Coding Journey Now!