I'm currently working on retrieving a child from Firebase with this code:
function fetchUserdetails() {
firebase.database().ref().child('login/').orderByChild('username').equalTo('ivanaldwin').on("value", function(snapshot) {
document.getElementById('fullname').innerHTML = snapshot.val().username;
console.log(snapshot.val()); //debug in console
snapshot.forEach(function(data) {
console.log(data.key);
alert('yep im working dood');
});
});
}
window.onload = fetchUserdetails();
But the code, if i use snapshot.val().username; will render undefined in the output. but if i use snapshot.val() only, the output will be [Object object]. Here's my firebase layout:
console.log(snapshot.val());?undefined.console.log(typeof snapshot.val());?[object Object]andobject