Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
localStorage For Saving Tasks Of To-Do List

I have a to-do list which I'm making, everything is working fine. I just have one problem with the saving.

Everytime I reload or close the page, all the data/tasks are removed. To prevent this, I want to use localStorage.

How am I supposed to do this?

Maybe save all the tasks right before the page is closed or reloaded. And when the page is loaded again, get all the data back, as it was.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Saving should be done whenever you add, remove or make a change to a todo. You can use localStorage.setItem(). If you have a JavaScript object or array of todos then you can JSON encode the data to be stored, because localStorage is a simple key-value pair structure for strings.

localStorage.setItem('todos', JSON.stringify(yourVariable));

On page load, you should read the todos from local storage and decode it:

let todos = [];
const todosJson = localStorage.getItem('todos');
if(todosJson){
    todos = JSON.parse(todosJson);
}
// run code which adds UI elements for the todos
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can store your todo list array like this:

var todos= [{id:0},titile:"buy something"];
localStorage.setItem("todoList", JSON.stringify(todos));

and you can read data from local storage like this

var storedTodos = JSON.parse(localStorage.getItem("todoList"));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda