This topic describes how you can manage application data in key-value format, using the Web storage.
Web Storage API
Web Storage
To manage application data, you can use the Web standard Web Storage API.
Note The Web storage can only store up to 5 MB of data for your application. If you need to store larger amounts, use the file system.
The Web storage can only store up to 5 MB of data for your application. If you need to store larger amounts, use the file system.
Use the following methods to manage the Web storage:
To store a key-value pair, use the setItem() method:
setItem()
localStorage.setItem('sample', 'This is just sample text.');
If the key does not exist, it is created with the specified value. If the key already exists, its value is updated.
To retrieve a key value, use the getItem() method:
getItem()
var value = localStorage.getItem('sample'); console.log(value);
If the key does not exist, the method returns null.
null
To remove a key, use the removeItem() method:
removeItem()
localStorage.removeItem('sample');
If the key does not exist, this method does nothing.