I was working in a vue project where I used a similar statement, and it worked nicely, now I'm need to do something similar with pure javascript for other project with Firebase but is not working. What I'm doing wrong, want to try to find the id inside the collection and then would like to get the group array. So the match(code below returns undefined)
//making snapshot to the realtime database
var dbValues = [ ];
var userOnStream = firebase.database().ref('users');
userOnStream.once('value', (childSnapshot) => {
var data = childSnapshot.val();
dbValues.push(data);
});
var userId = "0001"
var match = dbValues.find((x) => x.id == userId);
console.log(match); // this returns undefined
console.log(dbValues); //this returns correctly the array
And here you can find a sample of my data structure
{
"users" : [
{
"email" : "user3@emails.com",
"group": [ "slt1", "s1/index.html","Tue Jun 09 2021 10:00:00 GMT+0200 (Central European Summer Time)"],
"id" : "0001"
}, {
"email" : "user2@emails.com",
"group": [ "slt2", "s2/index.html","Tue Jun 09 2021 11:00:00 GMT+0200 (Central European Summer Time)"],
"id" : "0002"
}
...
]
}
Thank you for help an advice