I am trying to get the promise returned from another function. Here is my code:
function getData(){
var result = [];
return new Promise(function(resolve){
var query = firebase.database().ref('groups');
query.once('value').then(data => {
data.forEach(snapshot => {
var gdata = snapshot.val();
var grp = snapshot.key;
result.push(grp);
});
});
resolve(result);
});
}
I managed to print out the data for 'grp' variable from the function above. In my second fuction where I tried to access the data returned from promise:
However, from the second function, when I tried to print out in the .then(), nothing is actually printed out. Why is it so?
Thanks!