I am currently attempting to extract the name value from a promise retrieved from the Firebase Firestore database:
Just to provide some context, I have a collection of places that each contain information such as a name and a reference to an owner document, which only includes a name.
var names: any = [];
this.props.places.snapshot.docs.forEach((doc : any) => {
const place = doc.data()
place.ownerReference.get().then((snap : any) => {
name.push(snap.data().name);
console.log(names);
})
});
console.log(names);
The first console log displays the expected data, however, the last one returns an empty object. I understand this is due to the asynchronous nature of promises. How can I ensure the desired value is properly assigned to this variable?