title: How to get objects with unique values for specific keys from array of objects?
body: <p>I have an array of objects like below. </p>
  
  <pre><code> [{
          "_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"
      }]
  </code></pre>
  
  <p>I need to get objects with last <code>date</code>, which has unique <code>user</code>, <code>ownId</code> and <code>blockId</code>. By unique I mean that I will get only one <code>user</code> with same <code>ownId</code> same <code>blockId</code>. For this example I want to get only, since first object in array and last object in array has same <code>user</code>, <code>ownId</code> and <code>blockId</code>. </p>
  
  <pre><code>[{
              "_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"
          }]
  </code></pre>
  
  <p>What I tried is to itterate through array, but this way I can get only unique object within one key. I can't figure out how to have it with few keys.</p>
  
  <pre><code>stat.forEach(function(item) {
    var i = unique.findIndex(x =&gt; x.user == item.user);
    if (i &lt;= -1) {
      unique.push({
        id: item._id,
        user: item.user
      });
    }
  });
  </code></pre>