I have used a for loop but all the functions get triggered at once, the array.push is not working obviously and I get empty as results
const results = []
for (let x in obj) {
const url = 'https://api.test.com/v2/text?image_url=' + encodeURIComponent(obj[x]);
(async () => {
try {
const response = await got(url, {
username: apiKey,
password: apiSecret,
});
results.push({ response: response.body, url: obj[x] })
} catch (error) {
console.log(error);
}
})();
}
console.log('results :', results);