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

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

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