I'm trying to fetch data from a search engine API for a list of search queries. The results will be stored in another list. However, the return value is Promise{ <pending> } for all of them. What's the issue with my code?
Here's where I'm storing and calling the function to fetch the according API one-by-one:
let textWords = ["How to read stocks","Why is everyone so mean","Get rich fast"] // There's a list of search queries for which the search request is sent
let searchResults = [] // The list where I store the results
for (var t=0;t<textWords.length;t++) {
searchResults.push(runSearch(textWords[t]))
}
Where I fetch API:
async function runSearch(query) {
const url = `http://api.serpstack.com/search?access_key=my_key&query=${query}&engine=google`
const settings = {
"method": "GET"
}
try {
const response = await fetch(url, settings)
const final = await response.json()
return final
} catch(err) {
console.log(err)
}
}