HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Get the name of the first local storage item
The key() method returns name of the key with the specified index.
The key() method belongs to the Storage Object, which can be either a localStorage object or a sessionStorrage object.
Method | |||||
---|---|---|---|---|---|
key() | 4 | 8 | 3.5 | 4 | 10.5 |
Parameter | Description |
---|---|
index | Required. A Number representing the index of the key you want to get the
name of |
DOM Version: | Web Storage API |
---|---|
Return Value: | A String, representing the name of the specified key |
The same example, but using session storage instead of local storage.
Get the name of the first storage item:
var x = sessionStorage.key(0);
Loop through each local storage item and display the names:
for (i = 0; i < localStorage.length; i++) {
x = localStorage.key(i);
document.getElementById("demo").innerHTML += x;
}
StorageEvent reference: The key Property