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

274
Views
Why does indexeddb store.get not retrieve anything when using value from parameter, but works with same value as param when hardcoded?

I have made the following async function, which receives an "id" (integer) value as parameter.

But when I pass 1 as integer value for "id", the console.log output says "undefined", while if I instead replace the "id" in store.get() with a hardcoded 1, it works and shows correct output in console.log. I've tried console.log(id) and I can confirm that it receives the correct parameter value, which in this case is 1.

But I can't figure out why it acts differently when receiving the "id" value rather than a hardcoded one?

The store.get() function is part of standard indexedDB functions.

async getCollection(id) {
        let db = await idb.getDb()
        let trans = db.transaction(['collections'], 'readonly')
        let store = trans.objectStore('collections')
        let collection = store.get(id)

        return new Promise(resolve => {
            console.log(collection)
            collection.onsuccess = () => {
                console.log(collection.result)
            }
        })
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figured the answer. Confusion is, that when I logged the "id" value, it would show: 1 As if it was just a number. But if I did id === 1 check, it would be false. So I solved the issue by

let numberId = parseInt(id, 10)

After which I was able to use that value correctly in the store.get() method.

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!