O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting all key value pairs

We can retrieve all key-value pairs from local storage using a for loop and accessing the values of the key and value, using the key and getItem methods of the localStorage object:

for (var i = 0; i < localStorage.length; i++) {  console.log(localStorage.key(i)); // prints the key  console.log(localStorage.getItem(localStorage.key(i))); // prints the value}

We use the key method on the localStorage object, passing in the numeric index, i, to get the ith key in the storage. Similarly, we pass in the i numeric index to the key method of the localStorage object, in order to get the name of the key at the ith place in the storage. Note that the name of the key is obtained by the localStorage.key(i) method call and passed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required