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

215
Vistas
What's the best way to retrieve items with localforage and store their values on a dictionary?

I want to retrieve values with localforage and store them in a dictionary.

I've been trying this:

localforage.setItem('foo', 'bar');
baz = {
    foo: await localforage.getItem('foo')
}
console.log(baz.foo);

but it keeps giving me Uncaught SyntaxError: Unexpected identifier (at test.js:3:13) marking localforage.getItem('foo') on Line 3

When I enter this on console, it works as expected and prints bar

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

0

You should call the getItem in an async function to use await. Also, localforage.setItem returns a Promise, so you should use await to make it synchronous

async function doWork() {
   await localforage.setItem('foo', 'bar');
   baz = {
       foo: await localforage.getItem('foo')
   }
   console.log(baz.foo);
}
doWork()
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