Open In App

Node.js URLSearchParams.keys()

Last Updated : 14 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads