im trying to fetch data from firebase database, which im getting the data very well, but when i try to push all items received in an array, i obtain an array which i cannot iterate through like any other javascript array. here is my code:
var li = [];
useEffect(() => {
firebaseDB
.database()
.ref("collection")
.on("value", (data) => {
let all = data;
all.forEach((element) => {
li.push(element.val());
});
});
}, []);
console.log(li);
when i do console.log(li) , i get the li array which seems okay with the data, but when i try to do something with the array e.g. if i do console.log(li.length) , it prints 0 yet the array has multiple items in it. the problem is that my li array doesnt behave like an array. please assist me locate where the problem could be