JSFiddle - React, Tailwind, and code Playground
by A A
JavaScript
let stat = [
{
"_id": {
"$oid": "5d9a16764f66ef0017a738ee"
},
"user": "tVH3U5Va4cBFiATvAACD",
"team": "team1",
"question": "5d98c7109d0e1d0017e3d31f",
"date": {
"$date": "2019-10-06T16:29:40.240Z"
},
"correct": "true",
"ownId": "4",
"blockId": "1"
},
{
"_id": {
"$oid": "5d9a167c4f66ef0017a738ef"
},
"user": "tVH3U5Va4cBFiATvAACD",
"team": "team1",
"question": "5d98c7109d0e1d0017e3d31f",
"date": {
"$date": "2019-10-06T16:29:46.694Z"
},
"correct": "true",
"ownId": "4",
"blockId": "1"
},
{
"_id": {
"$oid": "5d9a16824f66ef0017a738f0"
},
"user": "tVH3U5Va4cBFiATvAACD",
"team": "team1",
"question": "5d98c7109d0e1d0017e3d31e",
"date": {
"$date": "2019-10-06T16:29:52.900Z"
},
"correct": "true",
"ownId": "5",
"blockId": "1"
}]
let unique = [];
stat.forEach(function(item){
var i = unique.findIndex(x => x.user == item.user);
if(i <= -1){
unique.push({id: item._id, user: item.user});
}
});
console.log("unique", unique)