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

565
Views
Get object array from axios and using return value call another axios function and append the output to first result

const request = { headers: { "Accept": "application", "Content-Type": "application/json", }, method: "GET", url: '', } as any;

        const result = await axios(request);

        result.data.data.map(async (ad: any) => {
            const request2 = {
                headers: {
                    "Accept": "application",
                    "Content-Type": "application/json",
                },
                method: "GET",
                url: '',
            } as any;

            const result2 = await axios(request2);
            ad.preview = result2.data.data[0].body;
        })

        return result.data.data;

preview key is not getting appended

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem is that the return statement is executed before the async map callbacks finish. Since you're not actually returning anything within your map, there's not much point in using it. Just use a for..of loop:

 const result = await axios(request); for (const ad of result.data.data) { const request2 = {...} const result2 = await axios(request2); ad.preview = result2.data.data[0].body; for return result.data.data;
over 4 years ago · Santiago Trujillo Report
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!