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

94
Views
How to assign an object to local storage instated of assigning with every single item?

I have an object that I want to assign to the local storage , I mean can you loop over it ? any idea how to implement this ? The end result is the keys in the object must be keys as well in the local storage after using the setitem, I sure know how set and get singular items but in other words I want to mount and object on an empty local storage object.

 const data = JSON.parse(object); // a prev localstroage object 
 console.log(data);
 localStorage.setItem(...Object.keys(data), ...Object.values(data));

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You have to use JSON.stringify(data); in order to store object in local storage.

Make sure you create your complete object in JavaScript itself (as per your requirement). And then once your object is ready, use JSON.stringify method to save objects in your local storage.

And to retreive back the data you will use JSON.parse() to get back the Object and then you can use any JavaScript methods to perform your tasks as per the requirement.

about 4 years ago · Juan Pablo Isaza Report

0

 //To set
 const obj = {
   key: "Hello World"
 }
 const strObj = JSON.stringify(obj);
 localStorage.setItem('strObj', strObj);

 //To get
 const strObjFromStorage = localStorage.getItem('strObj')
 const objFromStorage = JSON.parse(strObjFromStorage)
 console.log(objFromStorage);

about 4 years ago · Juan Pablo Isaza Report

0

You should be able to do so with JSON.stringify and JSON.parse :

// save object to localStorage
const myobj = {
    x: 1,
    y: 6
};
localStorage.setItem('key', JSON.stringify(myobj));
// fetch date as object from localStorage
let data = JSON.parse(localStorate.getItem('key'));
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!