title: How can I divide grouped array-object by length?
body: <p>I have the following data retrieved from a database</p>
  <pre><code>var members = [
    { &quot;name&quot; : &quot;a&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
    { &quot;name&quot; : &quot;b&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
    { &quot;name&quot; : &quot;c&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
    { &quot;name&quot; : &quot;d&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
    { &quot;name&quot; : &quot;e&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
    { &quot;name&quot; : &quot;f&quot;, &quot;department_id&quot; : 2, &quot;department_name&quot; : &quot;bbb&quot; },
    { &quot;name&quot; : &quot;g&quot;, &quot;department_id&quot; : 2, &quot;department_name&quot; : &quot;bbb&quot; }
  ];
  </code></pre>
  <p>The first step is to group this data by department name.</p>
  <pre><code>var groupedMembers = _.groupBy(members, &quot;department_name&quot;);
  
  ↓
  
  {
    &quot;aaa&quot; : [
      { &quot;name&quot; : &quot;a&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;b&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;c&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;d&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;e&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; }
    ],
    &quot;bbb&quot; : [
      { &quot;name&quot; : &quot;f&quot;, &quot;department_id&quot; : 2, &quot;department_name&quot; : &quot;bbb&quot; },
      { &quot;name&quot; : &quot;g&quot;, &quot;department_id&quot; : 2, &quot;department_name&quot; : &quot;bbb&quot; }
    ]
  }
  </code></pre>
  <p>From this state, I want to further split the object into every three objects.</p>
  <p>Ideally, I would like the array to be formatted in the following way</p>
  <pre><code>var expected = {
    &quot;aaa1&quot; : [
      { &quot;name&quot; : &quot;a&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;b&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;c&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; }
    ],
    &quot;aaa2&quot; : [
      { &quot;name&quot; : &quot;d&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; },
      { &quot;name&quot; : &quot;e&quot;, &quot;department_id&quot; : 1, &quot;department_name&quot; : &quot;aaa&quot; }
    ],
    &quot;bbb&quot; : [
      { &quot;name&quot; : &quot;f&quot;, &quot;department_id&quot; : 2, &quot;department_name&quot; : &quot;bbb&quot; },
      { &quot;name&quot; : &quot;g&quot;, &quot;department_id&quot; : 2, &quot;department_name&quot; : &quot;bbb&quot; }
    ]
  };
  </code></pre>
  <p>Can I solve that by using Underscore.js or lodash.js?
  If it's not too difficult, you can use other libraries or pure javascript implementations.</p>
  <p>Thank you.</p>