0

Hi I can't get the value of a specific index of an array. I don't know why because if I try to log the entire array it works but with a specific index it doesn't work

This is my code, I use cloud firestore to get the ID of a document and save it into array

var idUsers = [];
const users_list = document.querySelector("#users_list");

db.collection("utenti").get().then(function(querySnapshot) {

    querySnapshot.forEach(function(doc) {
        users_list.innerHTML += "<a href='utente.html' class='collection-item black-text'>" + doc.data().nome + " " + doc.data().cognome + " " + " </a>";
        idUsers.push(doc.id);
      });
});

console.log(idUsers);
console.log(idUsers[0]);

This is the result in Chrome console enter image description here

1

1 Answer 1

-1

Although it is considered to be a confusing statement, I assume that the operation is running asynchronously. Try to put a delay and then find value of idUsers[0] in order to find out the assumption.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.