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

98
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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