1//Set item
2localStorage.setItem('myCat', 'Tom');
3//Get item
4var cat = localStorage.getItem("myCat");
5//Remove item
6localStorage.removeItem("lastname");
7//Remove all items
8localStorage.clear();
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
1localStorage.setItem('myCat', 'Tom');
2
3var cat = localStorage.getItem('myCat');
4
5localStorage.removeItem('myCat');
6
7// Clear all items
8localStorage.clear();
9
1function setItem(name, value) {
2 localStorage.setItem(name, value);
3}
4function getItem(name) {
5 localStorage.getItem(name);
6}
7function deletItem(name) {
8 localStorage.removeItem(name);
9}
10function clearStorage() {
11 localStorage.clear();
12}
1localStorage.setItem('user_name', 'Rohit'); //store a key/value
2var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>javascript</title>
5 </head>
6 <body>
7 <input id="textbox" type="text" /><br><br>
8 <button id="btn">Save</button>
9 <br><br>
10<script type="text/javascript">
11var textbox = document.getElementById("textbox");
12var button = document.getElementById("btn");
13
14button.addEventListener("click", function(){
15 localStorage.name = textbox.value;
16});
17document.write(localStorage.name);
18
19</script>
20 </body>
21</html>
22