Javascript function finishing out of order — async

I have a simple function that calls a firestore collection and returns a list of companies. I iterate through the list and output the company name. Once it’s complete, I want to write “done”. function getCompanies() { firestore.collection(‘companies’) .listDocuments() .then(companies => { for(var i in companies) { companies[i].get().then(company => { console.log(company.name); }); } }).catch(err =>…

Details