1var testObject = { 'one': 1, 'two': 2, 'three': 3 };
2
3// Put the object into storage
4localStorage.setItem('testObject', JSON.stringify(testObject));
5
6// Retrieve the object from storage
7var retrievedObject = localStorage.getItem('testObject');
8
9console.log('retrievedObject: ', JSON.parse(retrievedObject));
1var person = { "name": "billy", "age": 23};
2
3localStorage.setItem('person', JSON.stringify(person)); //stringify object and store
4var retrievedPerson = JSON.parse(localStorage.getItem('person')); //retrieve the object
1function createItem() {
2 localStorage.setItem('nameOfItem', 'value');
3}
4createItem() // Creates a item named 'nameOfItem' and stores a value of 'value'
5
6function getValue() {
7 return localStorage.getItem('nameOfItem');
8} // Gets the value of 'nameOfItem' and returns it
9console.log(getValue()); //'value';
1localStorage.setItem('user_name', 'Rohit'); //store a key/value
2var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key
1let storage = window.localStorage;
2
3// set an item
4storage.setItem("highscore", 76);
5
6// get an item
7let highscore = storage.getItem("highscore");
8
9// remove an item
10storage.removeItem("highscore");
11
12// clear entire storage (NOT recommended as it also removes information about cookies, ad storage an so on)
13storage.clear();
14
1node-disk-storage a simple fast and secure local storage for nodejs,
2you can store any data using key and value.
3
4npm i node-disk-storage -S || yarn add node-disk-storage -S