-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12app.js
More file actions
36 lines (29 loc) · 895 Bytes
/
12app.js
File metadata and controls
36 lines (29 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// // Session storage
// sessionStorage.setItem("roll", 6);
// // Local storage
// localStorage.setItem("name", "Akriti");
// // To get value
// const name = localStorage.getItem("name");
// console.log(name);
// to remove local storage
// localStorage.removeItem("name");
// // to clear local storage
// localStorage.clear();
// To get the value from the form submitted
document.querySelector("form").addEventListener("submit", function (e) {
const task = document.getElementById("task").value;
let tasks;
if (localStorage.getItem("tasks") === null) {
tasks = [];
} else {
tasks = JSON.parse(localStorage.getItem("tasks"));
}
tasks.push(task);
localStorage.setItem("tasks", JSON.stringify(tasks));
alert("Task submited");
});
// To pull the value
const tasks = JSON.parse(localStorage.getItem("tasks"));
tasks.forEach(function (task) {
console.log(task);
});