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

157
Views
I need to call api inside a forEach and get those responses into a array and return. But it returns as an empty array in js(javascript)

Here is my code and the language is javascript.

    return new Promise(async (resolve, reject) => {
      let responses=  await axios.get("https://api.surveymonkey.com/v3/surveys/"+id+"/responses/bulk", {
        headers: {
          'Authorization':config
        }
      })

      resolve(responses.data)
    });
  }
responses_by_nicknames=async(nicknames)=>{

  return new Promise(async (resolve, reject) => {
   
    _.forEach(nicknames, function(value) {
      let  responses_by_nicknames2=[]

    let obj ={"nickname":value.nickname}
      console.log(value)
      _.forEach(value.surveys,async function(value2) {

    Promise.all([responses_by_id(value2.id)]).
       then(body => { 
      
                 responses_by_nicknames2.push(res)
        
      })
})
      console.log("!!@@",responses_by_nicknames2)
    })
resolve(responses_by_nicknames)
 })
 }

Console.log gives an empty array also. As I understood the console log and "resolve" execute before API is called.

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!