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
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;