Introducing LocalStorage

For the storage, we use local storage to store the book list persistently.

The local storage uses key value pairing.

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

1// save a string.
2localStorage.setItem(key, value);
3
4// load a string.
5localStorage.getItem(key);
6
7// remove an item.
8localStorage.removeItem(key);

LocalStorage uses string only for both keys and values. (Except Chrome)

Some browsers allow us to use the array notation to get/set local storage.

1localStorage["key here"] = "value goes here"; // set the value
2
3localStorage["key here"]; // get the value

But storing string is not quite useful. Next, we will see how we store objects.

What’s next? We’re going to take a look at “Converting objects into JSON string”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content