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

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