Using localStorage

suggest change

The localStorage object provides persistent (but not permanent - see limits below) key-value storage of strings. Any changes are immediately visible in all other windows/frames from the same origin. The stored values persistent indefinitely unless the user clears saved data or configures an expiration limit. localStorage uses a map-like interface for getting and setting values.

localStorage.setItem('name', "John Smith");
console.log(localStorage.getItem('name')); // "John Smith"

localStorage.removeItem('name');
console.log(localStorage.getItem('name')); // null

If you want to store simple structured data, you can use JSON to serialize it to and from strings for storage.

var players = [{name: "Tyler", score: 22}, {name: "Ryan", score: 41}];
localStorage.setItem('players', JSON.stringify(players));

console.log(JSON.parse(localStorage.getItem('players')));
// [ Object { name: "Tyler", score: 22 }, Object { name: "Ryan", score: 41 } ]

localStorage limits in browsers

Mobile browsers:

Browser Google Chrome Android Browser Firefox iOS Safari
Version 40 4.3 34 6-8
Space available 10 2 10 5MB

Desktop browsers:

Browser Google Chrome Opera Firefox Safari Internet Explorer
Version 40 27 34 6-8 9-11
Space available 10 10 10 5MB 10MB

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Web Storage:
* Syntax
* Using localStorage

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
43 Web Storage
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde