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

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

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