I'm currently using this function to get data from my Firebase project:
function getv(user)
{
var ref = firebase.database().ref('/users/'+user+'/points');
ref.once("value", function(snapshot) {
console.log(snapshot.val());
});
}
However, If I run this in the console, I get "undefined", and then the value:
If I try and assign it to a variable, and then get the value...
x = getv('Donut')
console.log(x)
I just get "undefined". I'm honestly at a complete loss as to why this is happening.
Any help is appreciated, I can provide more info if needed.
EDIT: Replacing console.log(snapshot.val())
with return snapshot.val()
still returns undefined.
EDIT 2: I've tried turning my function into in async function, which turns it into a Promise, however it still returns undefined
.
Async version:
async function getv(user)
{
var ref = await firebase.database().ref('/users/'+user+'/points')
ref.once("value", async function(snapshot) {
return await snapshot.val()
});
}