Here, I am initializing checkedinUsers with an empty array. I am passing the array as a parameter to getCheckedInUsers function. The array checkedinUsers is modified inside firebase db callback but in the scope outside the callback the value does not change.
var checkedinusers = [];
var getCheckedInUsers = function(checkedinUsers){
database.ref('/checkedin').once('value').then(function(snapshot) {
//console.log(snapshot.val());
if(snapshot.val()!== null){
var temp = snapshot.val();
for(var p in temp){
checkedinUsers.push(temp[p]);
}
console.log(checkedinUsers);
}else{
console.log("No checkedinUsers available");
}
});
console.log(checkedinUsers);
};
getCheckedInUsers(checkedinUsers);