2

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

1 Answer 1

2

The problem is that the return-statement runs before the async map-callbacks have finished. Since you're not actually returning anything inside your map, it does not make a lot of sense to use it though. 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;
}

return result.data.data;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.