Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Foreach async array issue

Jeremia777

New Coder
Hello,

i can't access the properties of the array,because it is empty, the console says to me "This value was evaluated upon first expanding".

Here is the code
JavaScript:
var querySnapshot = await getDocs(collection(db, "messages"));
  var arraymessages = [];
 
querySnapshot.forEach(async (doc) => {
    if(doc.id.split(":")[0] == nicknameUser || doc.id.split(":")[1] == nicknameUser){
          
            
          var messagesField = await getDocs(collection(db, "messages/"+doc.id+"/messages"));
          var messagesa = [];
          messagesField.forEach((messageDoc) => {
            messagesa.push(messageDoc.data().message);
          })
          var messages = {'sender': doc.id.replace(/:/g, "").replace(nicknameUser, ""), 'message' : messagesa};
          arraymessages.push( messages);
          
     }     
    else{
        
    }
});

console.log(arraymessages)
 
It could help your case if you post complete code that someone can actually run. Also if you get an error, indicate exactly the line that the error is occurring on. Doesn't guarantee success, but with neither condition met I think your chances are very slim.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom