function getUsersEmail() {
const dbRef = ref(getDatabase());
get(child(dbRef, `users/` )).then((snapshot) => {
if (snapshot.exists()) {
console.table(snapshot.val());
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
}
I was able to output the database to the console. I would like to output only the email addresses of users.
JSON File
{
"users": {
"2Le5WxOGnWWrkshsEqjeSIq527O2": {
"email": "[email protected]",
"password": "qweqwe"
},
"2jn1YmI9twce3ylEP8wiu5QhUDf1": {
"email": "[email protected]",
"password": "qweqwe"
},
CodePudding user response:
To retrieve all users and output only their email addresses:
get(child(dbRef, `users/` )).then((snapshot) => {
snapshot.forEach((child) => {
console.log(child.val().email);
})
});