HTML | DOM Storage key() Method
The DOM Storage key() Method is related to the Storage object and is used to return the name of the key with the specified index. Storage object can be either a localStorage or sessionStorage Object.
Syntax:
- Local storage:
localStorage.key(index)
- Session storage:
sessionStorage.key(index)
- Before Click:

- After Click:

- Google Chrome 4
- Internet Explorer 8
- Firefox 3.5
- Opera 10.5
- Safari 4
- HTML | DOM Storage removeItem() Method
- HTML | DOM Storage getItem() Method
- HTML | DOM Storage setItem() Method
- HTML | DOM Local Storage clear() Method
- HTML | DOM Storage Event
- HTML | DOM Storage length Property
- LocalStorage and SessionStorage | Web Storage APIs
- HTML | DOM contains() Method
- HTML | DOM focus() Method
- HTML | DOM createElement() Method
- HTML | DOM removeAttributeNode() Method
- HTML | DOM createComment() Method
- HTML | DOM hasFocus() Method
- HTML | DOM hasAttributes() Method
- HTML | DOM getAttributeNode() Method
Parameters: It accepts a parameter i.e. index to get the name of the key with that particular given index.
Return Values: It returns the name of the key in the form of the string.
Below is the HTML code to show the working of HTML DOM Storage key() Object:
Example:
<!DOCTYPE html> <html> <head> <title> HTML DOM Storage key() Method </title> <!-- Script to get the name of the key --> <script> function myGeeks() { var key = localStorage.key(0); document.getElementById( "geeks").innerHTML = key; } </script> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM Storage key() Method</h2> <br> <button onclick="myGeeks()"> Submit </button> <p id="geeks"></p> </body> </html> |
Output:
Supported Browsers: The browser supported by DOM Storage key() Method are listed below:
Recommended Posts:
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.



