I am a newbie to Javascript and I am in the middle of solving the last part of my program. However, I am experiencing difficulties with async await function as I am trying to get and store data from multiple requests and push it into an array which I want to use outside in the function. Later I want to render the content of this array(the quotes) and render it to the browser. Inside in my inner loop, I am able to console log my array but when I am trying to return it or use the function itself I ran into a problem. Any ideas?
I have an array of URLs which I am using to do multiple calls with because I need a certain amount of items in my array and the API provided doesn't get me more than 25 quotes per response.
const getQuotes = () => {
let completeQuotesArray = [];
const quotesPromises = urls.map(async url => {
const response = await axios.get(url);
console.log(response);
return response.data.quotes;
});
for (const quotesPromise of quotesPromises) {
let quotesArray = await quotesPromise;
for (let i = 0; i < quotesArray.length; i++) {
let quote = quotesArray[i].body;
if (quote.length < 150) {
completeQuotesArray.push(quote);
}
}
}
return completeQuotesArray;
}