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

248
Vistas
How do I save all my created variables to local storage? (Javascript/HTML)

Straight to the point. I am in the process of making a game right now, I have come to the point where I want to save all my variables to the local storage.

And YES I know the good ol' way:

localStorage.setItem("var1", 5)

var1 = parseInt(localStorage.getItem("var1"))

That's all good and all, but I have WAYYY to many variables to type all that out manually, Is there a way to save all my variables to local storage with only a couple lines of code? then on refresh, set all variables back to there corresponding value in local storage

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

0

Why not instead of using many variables just use one object? Then you save it once and read it once:

let variables = {
    "var1" : 5,
    "var2" : 10
};
 
localStorage.setItem("vars", JSON.stringify(variables));
...
let variables = JSON.parse(localStorage.getItem("vars"));
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