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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

keyA
keyB

Example2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

name
age

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.