Kaluma
Search…
Storage
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.

Object: Storage

storage.length

  • <number>
Returns the number of data items in the storage.
1
storage.setItem("key1", "value1");
2
storage.setItem("key2", "value2");
3
console.log(storage.length); // 2
Copied!

storage.getItem(key)

  • key <string>
Return the value associated with the given key.
1
storage.setItem("key1", "value1");
2
var value1 = storage.getItem("key1");
3
var value2 = storage.getItem("key2"); // null
4
console.log(value); // "value1"
Copied!

storage.setItem(key, value)

  • key <string>
  • value <string>
Add the key with the value to the storage.
1
storage.setItem("key1", "value1");
2
var value1 = storage.getItem("key1"); // "value1"
3
storage.setItem("key1", "new value");
4
value1 = storage.getItem("key1"); // "new value"
Copied!

storage.removeItem(key)

  • key <string>
Remove the data item associated with the given key.
1
storage.setItem("key1", "value1");
2
storage.removeItem("key1");
3
var value1 = storage.getItem("key1"); // null
Copied!

storage.clear()

Remove all the data items in the storage.
1
storage.setItem("key1", "value1");
2
storage.setItem("key2", "value2");
3
storage.clear();
4
var value1 = storage.getItem("key1"); // null
5
var value2 = storage.getItem("ket2"); // null
Copied!

storage.key(index)

  • index <number>
  • Returns: <string>
Returns the key string of the given index.
1
storage.setItem("key1", "value1");
2
storage.setItem("key2", "value2");
3
console.log(storage.length); // 2
4
console.log(storage.key(0)); // "key1"
5
console.log(storage.key(1)); // "key2"
Copied!
Last modified 30d ago