I am trying to return return a value and display it in the console.(for now)
The user ID is passed to a "function".
The function will check for this ID in a database and should return the userName.
I know that the correct data is found because the console.log returns the correct infirmation in function itself (see: THIS WORKS)
But the returned value is "undefined" when used return childData.userName;
Calling the function
console.log( f_returnUserDetails(uid)
The function itself
function f_returnUserDetails(a){
console.log(a)
var key;
var childData;
firebase.database().ref('/dataman-blabla/').orderByChild("uid").equalTo(a).on('value', function (snapshot) {
snapshot.forEach(function(childSnapshot) {
key = childSnapshot.key;
childData = childSnapshot.val();
console.log(childData.userName); //THIS WORKS
return childData.userName; //THIS DOES NOT
});
});
};