title: How to change d3.nest to group using reverse
body: <p>I'm trying to update some old code for D3 v5 to use the newer group command. I'm not familiar with the sorting, mapping methods but I have rewritten it partially but I do not know how to duplicate the reverse function.</p>
  <p>Here's the original:</p>
  <pre><code>const years = d3.nest().key(d =&gt; d.date.getUTCFullYear()).entries(dateValues).reverse();
  </code></pre>
  <p>For D3 v7 I've gotten this far:</p>
  <pre><code>const years = d3.group(dateValues, d =&gt; d.date.getUTCFullYear());
  </code></pre>
  <p>However I still need to modify the array structure to duplicate what happens with .reverse().</p>
  <p>The group function leaves it as:</p>
  <pre><code>Map(10) { 2010 → (276) […], 2011 → (365) […], 2012 → (366) […], 2013 →
  (365) […], 2014 → (365) […], 2015 → (365) […], 2016 → (366) […], 2017 → (365) […], 2018 → (365) […], 2019 → (103) […] }
  </code></pre>
  <p>Whereas the original next and reverse left it as an array of key and values</p>
  <pre><code>Array(10) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…} ]
  
  0: Object { key: &quot;2019&quot;, values: (103) […] } ​ 
  
  1: Object { key: &quot;2018&quot;,values: (365) […] } ​ 
  
  2: Object { key: &quot;2017&quot;, values: (365) […] } ​
  
  3: Object { key: &quot;2016&quot;, values: (366) […] } ​ 
  
  4: Object { key: &quot;2015&quot;, values: (365) […] }
  
  5: Object { key: &quot;2014&quot;, values: (365)[…] } ​ 
  
  6: Object { key: &quot;2013&quot;, values: (365) […] } ​ 
  
  7: Object { key: &quot;2012&quot;, values: (366) […] }
  
  8: Object { key: &quot;2011&quot;, values:(365) […] }
  
  9: Object { key: &quot;2010&quot;, values: (276) […] }
  </code></pre>
  <p>Sorry in advance if I'm not using the correct terminology but I don't work with JS or D3 often. Thanks.</p>
  <hr />
  <p>Edit: the data is in json format. Example:</p>
  <pre><code>[{
      &quot;Date&quot;: &quot;2017-08-30&quot;,
      &quot;AnswerCount&quot;: &quot;9510&quot;
  },
  {
      &quot;Date&quot;: &quot;2010-05-23&quot;,
      &quot;AnswerCount&quot;: &quot;2096&quot;
  },
  {
      &quot;Date&quot;: &quot;2014-01-10&quot;,
      &quot;AnswerCount&quot;: &quot;11451&quot;
  },
  {
      &quot;Date&quot;: &quot;2019-03-23&quot;,
      &quot;AnswerCount&quot;: &quot;4393&quot;
  },
  {
      &quot;Date&quot;: &quot;2013-03-07&quot;,
      &quot;AnswerCount&quot;: &quot;11811&quot;
  }
  ]
  </code></pre>
  <hr />
  <p>Edit: doing this gets it closer to the original structure:</p>
  <pre><code>            var year_map = d3.group(dateValues, d =&gt; d.date.getUTCFullYear());
              var years=Array.from(year_map);
              years.reverse();
  </code></pre>
  <p>However it is not in the Key: Values sort of structure but rather</p>
  <pre><code>Array(10) [ (2) […], (2) […], (2) […], (2) […], (2) […], (2) […], (2) […], (2) […], (2) […], (2) […] ]
  ​
  0: Array [ 2019, (103) […] ]
  ​
  1: Array [ 2018, (365) […] ]
  ​
  2: Array [ 2017, (365) […] ]
  ​
  3: Array [ 2016, (366) […] ]
  ​
  4: Array [ 2015, (365) […] ]
  ​
  5: Array [ 2014, (365) […] ]
  ​
  6: Array [ 2013, (365) […] ]
  ​
  7: Array [ 2012, (366) […] ]
  ​
  8: Array [ 2011, (365) […] ]
  ​
  9: Array [ 2010, (276) […] ]
  </code></pre>
  <p>Where the object is an array of objects structured like this:</p>
  <p><a href="https://i.stack.imgur.com/hGb8O.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hGb8O.jpg" alt="enter image description here" /></a></p>
  <p>How would I make this an array of objects with a Key and Values in JS?</p>