Iterating over a storage by indices in JavaScript

The localStorage object is not iterable. However, it does have indices and length. This means that you can iterate through the entries using the usual for loop with a counter:

for (let i = 0; i < localStorage.length; i++) { let key = localStorage.key(i); let val = localStorage.getItem(key); console.log(val); }

On button click, output with loop all the entries from the local storage.

enru