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

131
Views
Assign nested object property

I was unable to retrieve the kitItems object when I try to access it outside the foreach loop.

This works

 for(i=0;i<customer.kit.length;i++){
        const kitItems = await KitItem.findAll({
            where :{
                kit_id:customer.kit[i].id
            }
        })       
       customer.kit[i].kitItems=kitItems                
    }
console.log(customer.kit[0].kitItems)   // this works 

This does not work

    customer.kit.forEach(async (kit,index) => {
        const kitItems = await KitItem.findAll({
            where :{
                kit_id:kit.id
            },
            raw:true
        })
       
       customer.kit[index].kitItems=kitItems         
    });
console.log(customer.kit[0].kitItems)   // this does not work 

What did I miss and better yet, how can I refactor this and use the new ES6/7 methods?

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!