I'm having a trouble with assigning return value from Firebase call function to my global variable. This is my function:
function getThePushNameById( path , id ){
path.once( 'value', function( data ){
if( data.child('id').val() != id ){
data.forEach( function( newData ){
var base = new Firebase( path.child( newData.name() ).toString() );
getThePushNameById( base, id );
})
}else{
//finishes the function when path is founded - returns the value
return path.name();
}
})
}
and this is the other file where I set the request:
var base = new Firebase(path/to/my/base);
var output = getThePushNameById( base , 2 )
console.log(output);
So my problem is that console.log doesn't wait for output to be defined, but runs itself and logs undefined. And my question is if someone knows how can I make console.log wait for value?