I'm trying to retrieve some Data from Firebase (which works perfectly), but my colleague needs that I return the value of a snapshot as an Array, so that he can use it in another file. And as far as I know, it's impossible knowing that the value event is Asynchronous.
here's an example:
function getData() {
let current = [];
qRef.on("value", function (snapshot) { //qRef is the reference to my DB
current = snapshot.val();
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
return current; //expected value is the returned data from the snapshot
}
Is there any alternative solution? Thanks.
snapshot.val()in the value function