Reputation: 9731
I was wondering if I can by any chance store more than one key on localStorage ? For instance :
localStorage.setItem("a_key", a_value);
localStorage.setItem("another_key", another_value);
Is it possible to do so ? If not what do you advise I shall do as a workaround that, because I need to have two keys or variables stored on the clients side ?
Upvotes: 2
Views: 4286
Reputation: 166041
Yes. You can store multiple key/value pairs in local storage (and session storage). From the web storage spec (emphasis added):
Each Storage object provides access to a list of key/value pairs, which are sometimes called items. Keys are strings. Any string (including the empty string) is a valid key. Values are similarly strings.
...
The length attribute must return the number of key/value pairs currently present in the list associated with the object.
Upvotes: 5