When I console.log my array it shows that the length is zero. I checked that it was an array using Array.isArray
which returned true
. Also printed out the array values to make sure they exist and it shows in the console:
[]
0: "a"
1: "b"
2: "c"
3: "d"
length: 4
__proto__: Array(0)
I see that __proto__: Array(0)
and I'm assuming this means it's a 0 length Array but how do I make it non-zero length so that I can iterate through it?
A thought I had is that this function might be asynchronous but I'm not really sure how to work around that.
Code for reference:
var list=[]
//getting data from a database
snapshot.forEach(function (node) {
list.push(node.val())
console.log(node.val()) //values print out
})
console.log(list) //array is length zero
I'm basically trying to add a for loop after this code to read through each value and use it for something else. However I can't iterate through the array because it registers as empty.