For example, given this array of objects:
[
{ userid: "5", articleid: "3"},
{ userid: "5", articleid: "3"},
{ userid: "5", articleid: "3"},
{ userid: "1", articleid: "2"}
]
I want to display the values this way Without repetition inside the loop:
[
{ userid: "5", articleid: "3"},
{ userid: "1", articleid: "2"}
]
The code used is javascript
var newMessage = '';
function realTime(){
db.collection('chat').where('userid', '==', <?php echo $id; ?>)
.orderBy('time')
.onSnapshot(function(snapshot) {
newMessage = '';
snapshot.docChanges().forEach(function(change) {
if (change.type === "added") {
//console.log(change.doc.data());
const elements = [change.doc.data()];
console.log([...new Set(elements.map(JSON.stringify))].map(JSON.parse));
}
});
if (chatHTML != newMessage) {
$('.msg_body').append(newMessage);
}
});
}