I'm trying to work out why this function isn't pushing my item
as an object to the availableProviders
array within my if
statement.
serviceProviders.on('value', function(snapshot) {
var availableProviders = [];
snapshot.forEach(function(childSnapshot) {
var key = childSnapshot.key();
providers.on('value', function(snap) {
if (snap.hasChild(key)) {
var item = snap.child(key);
availableProviders.push(item);
}
});
});
console.log(availableProviders);
});
For some reason my console.log
at the end just returns an empty array.
Any reason why my item
isn't being pushed. Any help is appreciated. Thanks in advance!