0

When i print my item counter the value is still 0 even there is a data on it but if i print the itemcount below on increment it shows the right value. Please help me I also use firebase on this

I want the right value of item counter because it always shows a 0 value

here is the code :

var itemCounter = 0;

get(queGadget).then((snapshot)=>{
    snapshot.forEach(childSnapshot => {
      ++itemCounter;

    });

})

console.log(itemCounter)
  • Console.log happens prior to .then due to the asynchronous nature of promises. Put console log inside then. – James Nov 11 '22 at 14:19

0 Answers0