Hi guys so I have this data:
When I console.log(Object.entries(data)) I get this:
https://pastebin.com/jPyRuxFX
I always know that in this object is my userID: lwcIQTcpAae4e38hrD2K5Ar76W93 members object and messages object. I want to filter it so there would be only other user data. Another userID could be any unique key It' is in object but I don't have it in any variable. So I need to filter out all data. This is what I tried:
getChats = _userId => {
let data;
let usersData = [];
var readedData = firebase
.database()
.ref('chats')
.orderByChild('members/' + _userId)
.equalTo(true);
readedData.once('value', snapshot => {
data = snapshot.val();
const temp = { ...data };
const filtered = Object.entries(data).map(duom =>
duom
.filter(user => user !== firebase.auth().currentUser.uid)
.filter(user => !user.members)
.filter(user => !user.messages),
);
console.log('filtered data: ' + JSON.stringify(data[filtered[0][0]]));
this.setState({ chats: data, usersData: usersData });
return true;
});
};
But result is this : [["-M6cy1JNy1V5cs35StW-"],["-M4O-aIxt9w2iKuCDweN"],["-M4NzlagjmeFH7IR_Api"]] What I do wrong, how to eddit this filter?
The result I want is in each object:
"tempuser":{ "username":"Egle", "profile_picture":"https://scontent.fkun1-1.fna.fbcdn.net/v/t1.0-9/38612482_1935470283165234_1771800590876147712_n.jpg?_nc_cat=111&_nc_sid=85a577&_nc_ohc=3rVHabbNJ3kAX9_0FBq&_nc_ht=scontent.fkun1-1.fna&oh=4277fff9a1441726bbf0efe18b44fae0&oe=5E9AA1F7" }