I am building a web app with JS and firebase as my DB, but I'm struggeling to call on my gotData function to get it's return value.
var dbRef = firebase.database().ref('testing');
function reading(){
dbRef.on('value', gotData,errData) ;
}
function gotData(data){
var tests = data.val();
var keys = Object.keys(tests);
var length = keys.length;
var k = keys[lengthe-1];
console.log(k)
console.log(data)
return k;
}
function errData(err){
alert('error')
}
The code works and I get the documentID of the newest document returned, but I fail to call on this value.
I tried:
var fbid = gotData(data);
but I get an data is not defined error. From my understanding data is just used to reference to the Firebase data so I can do operations on it. What do I need to do, so that I can call the function with it's data ?