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

214
Views
¿Cómo puedo obtener un valor de elemento específico del objeto en el almacenamiento local?

Estoy tratando de obtener el valor de "ciudad" (en el caso de Oporto, Lisboa, Leiria, Londres) del almacenamiento local y ponerlo en una variable. Deseo hacer esto en un bucle y usar cada nombre de ciudad en una función.

Ahora estoy aquí:

 Object.entries(localStorage).map(([id, valueJSON]) => { cityName = JSON.parse(JSON.stringify(localStorage.getItem('persist:root', 'allWeather', 'city'))); console.log(cityName)

Mi regreso es este:

{"allWeather":"[{"id":0.47266066302275545,"city":"Oporto"},{"id":0.8669553925029849,"city":"Lisboa"},{"id":0.5502373167192611,"city": "Leiria"},{"id":0.19655712000371484,"city":"Londres"}]","_persist":"{"version":-1,"rehidratada":true}"}

¿Cómo puedo hacer esto? Agradezco cualquier ayuda.

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

0

Prueba esto:

 const cities = // Parse the localstorage item to object JSON.parse(localStorage.getItem('persist:root', 'allWeather', 'city')) // Get the allWeather property .allWeather // Get the city properties only .map(weather => weather.city);
about 4 years ago · Juan Pablo Isaza Report

0

  • Debe convertir la cadena del objeto a JSON usando JSON.parse

  • [{ city }] esta parte no está bien. cambiarlo a city

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!