Reputation: 833
I'm able to display the correct data from my Firebase child in the console with the following code:
var ref = firebase.database().ref('requests');
ref.on('value', gotData, errData);
function gotData(data) {
var scores = data.val();
console.log(scores);
}
Which displays the following in the console:
So when I try to use this snippet of code to retrieve the email:
function gotData(data) {
var scores = data.val();
console.log(scores);
var keys = Object.keys(Email);
console.log(keys);
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
var emails = email[k].email;
console.log(emails);
}
}
it's displaying the following error:
but I'm not fully understanding why I'm getting this error when this is very similar to other peoples solution.
Anyone know why I'm getting this error when there is an actual value for the email key?
Upvotes: 0
Views: 313
Reputation: 80914
To get the email
simply to do this:
var ref = firebase.database().ref('requests');
ref.on('value', function(snapshot) {
snapshot.forEach(function(child) {
var datas = child.val();
var email=child.val().Email;
});
});
Assuming you have this database:
requests
randomid
Email: email_here
You need to be iterating inside the randomid to be able to access the property Email
Upvotes: 1