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

180
Vistas
How to get the public property value of a class?

I created a function in a class that inserts a data in the users table. I have a data property that stores the all inserted data. My current problem is, whenever I will try to log the data, it returns an empty array.

I can confirm that there is nothing wrong with prisma, because the it logs the actual inserted data (there is a console log in the code below). I suspect that this could be promise issue, but I can't confirm and until now I'm unable to find solution.

I have tried wrapping the forEach by Promise.all(..), but it returns a typescript error. I would appreciate any comment or suggestion, since I already burned over an hour of this problem.

my class:

class StudentFac {
  public data: IProvider[] = []

  public run = async () => {
    ....
  
    data.forEach(async (data, index) => {
      this.data[index] = await prisma.user.create({ data })
      console.log(this.data[index])  <------------ it displays actual data here
    })
  }
}

how I use:

const studentFac = new StudentFac()
await studentFac.run();

console.log(studentFac.data) <--------------- returns empty array
about 4 years ago · Juan Pablo Isaza
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