title: Javascript - getting data out of array of objects
body: <p>I got this sample data.</p>
  
  <pre><code>"array" : [
      {"Id" : "1", "preferred" : false}, 
      {"Id" : "1", "preferred" : true }, 
      {"Id" : "2", "preferred" : false}, 
      {"Id" : "2", "preferred" : false},]
  </code></pre>
  
  <p>And i would like to get out of it something like this.</p>
  
  <pre><code>"array2":[{"Id": 1, numOfTrue: 1, numOfFalse: 1},{"Id": 2, numOfTrue: 0, numOfFalse: 2}]
  </code></pre>
  
  <p>What i got so far is a way how to get unique id form initial array.</p>
  
  <pre><code>const unique = [...new Set(array.map(item =&gt; Id))];
  </code></pre>
  
  <p>Next step would be some forEach over array and comparing Id values and setting some counters for that boolean value. So before i dive into forEach solution i would like to ask if there is another way with using .<code>filter()</code> and <code>.reduce()</code> methods.</p>