I am not able to manage correctly the sync, async, and promises part related to Firestore query. I provide you a simplified version of my scenario. I have different categories of items and I want to display all the category with all items related in a particular way. This is defined by the function Display, that accept as a parameter an array, that contains items belonging to a category.
categories=["ct1","ct2"]
....
async function getItems(category){
let items=[]
const snap = await db.collection("items").where("category","array-contains",category).get()
snap.forEach((doc=>trainers.push(doc.data())))
return items;
}
....
LOOP ON CATEGORIES
Display(getItems(category))
Now the problem is the part of handling Promise. getItems return a promise not an array. How can I solve the problem and passing the data retrieved from Firestore to display function?