Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!