You can access the window.localStorage method
By setting data to the localStorage
localStorage.setItem('key', value );
And also getting
localStorage.getItem('key', value);
You can also save an array by passing data
// let’s say am saving an array of books with objects values
localStorage.setItem('books',JSON.stringify(books));
let books = localStorage.getItem('books');
books = JSON.parse(books);
I hope this helps
To save an item to local storage:
localStorage.setItem(variable, 'value');
To get data from local storage:
let var = localStorage.getItem(variable);
Take a look at the documentation. It is really simple.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
I have a simple to do app that creates to dos and displays them to the screen. However, I wan’t to save these to local storage so if someone leaves the page and returns, reloads the page, etc. the to do items remain.
I need to finish it until tomorrow and i’m struggling since hours to implement a localStorage 🙁
I appreciate every help. Thanks in advance.
here is my code on js.fiddle.net :
if (event.target.classList.contains('js-delete-todo')) {
const itemKey = event.target.parentElement.dataset.key;
todoloeschen(itemKey);
}
https://jsfiddle.net/mymyyy/haset7gc/
I will give you simple tip on top of the other answers. Always and always program in English language. There is nothing more frustrating in life than finding a source code that is written in mongoloid and you can’t understand anything. Your fiddle would be more helpful if variable names etc would be in English.