I’ve a problem with my code (typescript):
async getAllServers(@Res() response) {
const servers = await this.serverService.getAllServers();
let bot = []
servers.map(async server => {
console.log(server.id)
bot.push(await this.serverService.getInfo(server.id));
console.log(bot)
})
return response.status(HttpStatus.OK).json({
bot,
servers
})
}
This function need to return 2 array, but the second array (bot) is always empty.
This is because return is executed before the loop.
How I can execute the return when the loop finish?
Thanks in advance and sorry for bad english.