The storage
object provide the functions for storing key-value items in local persistent storage.
Please note that typically internal flash memory is used to store data items. As you know flash memory has finite number of write/erase cycles (less than tens of thousands), so please do not use this storage API for the jobs need frequently write/erase cycles.
<number>
Returns the number of data items in the storage.
storage.setItem("key1", "value1");storage.setItem("key2", "value2");console.log(storage.length); // 2
key
<string>
Return the value associated with the given key.
storage.setItem("key1", "value1");var value1 = storage.getItem("key1");var value2 = storage.getItem("key2"); // nullconsole.log(value); // "value1"
key
<string>
value
<string>
Add the key with the value to the storage.
storage.setItem("key1", "value1");var value1 = storage.getItem("key1"); // "value1"storage.setItem("key1", "new value");value1 = storage.getItem("key1"); // "new value"
key
<string>
Remove the data item associated with the given key.
storage.setItem("key1", "value1");storage.removeItem("key1");var value1 = storage.getItem("key1"); // null
Remove all the data items in the storage.
storage.setItem("key1", "value1");storage.setItem("key2", "value2");storage.clear();var value1 = storage.getItem("key1"); // nullvar value2 = storage.getItem("ket2"); // null
index
<number>
Returns: <string>
Returns the key string of the given index.
storage.setItem("key1", "value1");storage.setItem("key2", "value2");console.log(storage.length); // 2console.log(storage.key(0)); // "key1"console.log(storage.key(1)); // "key2"