key(): Passed a number to retrieve nth key of a LocalStorage.
Syntax
Syntax for Key() Method:
var KeyName = localStorage.key(index);
localStorage.key() Method Example
The following function iterates over the local storage keys:
function forEachKey(callback) {
for (var i = 0; i < localStorage.length; i++) {
callback(localStorage.key(i));
}
}
The following function iterates over the local storage keys and gets the value set for each key:
for(var i =0; i < localStorage.length; i++){
console.log(localStorage.getItem(localStorage.key(i)));
}
Reference
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course