Trying to push an array retrieved from firestore, but encountering issues where the array appears undefined.
Here is the code snippet in question:
const temp = [];
const reference = firestore.collection("users").doc(user?.uid);
firestore
.collection("countries")
.get()
.then((result) => {
result.forEach((item) => {
temp.push(item.data());
});
});
console.log(temp); //works
console.log(temp[0]); //does not work
The console displays the following results:
https://i.stack.imgur.com/STV4G.png
Upon observation, it seems that the resulting array doesn't match the expected format, such as (3) [{...}, {...}, {...}]
, instead showing just []
.
If anyone can provide insight into why this issue is occurring, it would be greatly appreciated. Thanks!