1

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);
AL.
  • 36,815
  • 10
  • 142
  • 281
bodhi
  • 203
  • 3
  • 14
  • @baao - can you refer to the existing question which is similar to this one? – bodhi Mar 16 '17 at 18:55
  • Sure, just click the link, read the answer and you know what's happening – baao Mar 16 '17 at 19:03
  • Thanks @baao! I see that. Should I delete my question? – bodhi Mar 16 '17 at 20:07
  • No, no need for that. Duplicates are always good for other people to find the right answer! Also, appart from being a dupe, your question was a good one – baao Mar 16 '17 at 20:08

0 Answers0