Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
how to find length of an array in javascript

I am working with firebase for the first time. For that I am using Firestore. For getting all the messages I use Firebase built in method querySnapshot; Here i am getting all the rows as an object, where I declare a global variable as an array and try to push each and every object into that array. All was perfect. I got the array with all the messages as I want. But I want to get the length of an array. And I dont know every time I got 0 as an output where It have two rows.Lets Look at the Image for more better understanding enter image description here

Please help me solve this..

enter image description here Here is the utput i get

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I suppose showMessages() called earlier than you push anything to user_messages array in onSnapshot callback.

about 4 years ago · Juan Pablo Isaza Relatório

0

onSnapshot lets you listen for snapshots. That means that you cannot guarantee that your handler would have been called even once before showMessages is invoked.

You could reorder your control flow like this:

// ...

user_chats.onSnapshot((querySnapshot) => {
    querySnapshot.forEach(doc => {
        user_messages.push(doc.data());
    });
    showMessages();
});

// ...
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda