title: format object array to grouped nested array object to generate antd tree table
body: <p>I get the following array object from response and I need to implement <code>antd</code> tree table in my react application using this array object.</p>
  <pre><code>const students=[
  {
  &quot;index&quot;: &quot;5260574&quot;,
  &quot;studentName&quot;: &quot;David Sinclair&quot;,
  &quot;marks&quot;: &quot;177&quot;,
  &quot;gender&quot;: &quot;M&quot;,
  &quot;resultId&quot;: 16,
  &quot;province&quot;: {
    &quot;code&quot;: &quot;1&quot;,
    &quot;name&quot;: &quot;Andregan&quot;
  },
  &quot;county&quot;: {
    &quot;name&quot;: &quot;Silk&quot;,
    &quot;code&quot;: &quot;21&quot;
  },
  &quot;city&quot;: {
    &quot;code&quot;: &quot;234&quot;,
    &quot;name&quot;: &quot;Meegan&quot;
  },
  &quot;rural&quot;: {
    &quot;code&quot;: &quot;41&quot;,
    &quot;name&quot;: &quot;Thumphil&quot;
  },
  &quot;canEvaluate&quot;: true
  },
  {
  &quot;index&quot;: &quot;5259991&quot;,
  &quot;studentName&quot;: &quot;KALURA GEETH DAMS&quot;,
  &quot;marks&quot;: &quot;177&quot;,
  &quot;gender&quot;: &quot;M&quot;,
  &quot;resultId&quot;: 17,
  &quot;province&quot;: {
    &quot;code&quot;: &quot;1&quot;,
    &quot;name&quot;: &quot;Andregan&quot;
  },
  &quot;county&quot;: {
    &quot;name&quot;: &quot;Silk&quot;,
    &quot;code&quot;: &quot;21&quot;
  },
  &quot;city&quot;: {
    &quot;code&quot;: &quot;234&quot;,
    &quot;name&quot;: &quot;Meegan&quot;
  },
  &quot;rural&quot;: {
    &quot;code&quot;: &quot;41&quot;,
    &quot;name&quot;: &quot;Thumphil&quot;
  },
  &quot;canEvaluate&quot;: true
  },
  {
  &quot;index&quot;: &quot;5260534&quot;,
  &quot;studentName&quot;: &quot;Mathew Jenkins&quot;,
  &quot;marks&quot;: &quot;157&quot;,
  &quot;gender&quot;: &quot;M&quot;,
  &quot;resultId&quot;: 21,
  &quot;province&quot;: {
    &quot;code&quot;: &quot;1&quot;,
    &quot;name&quot;: &quot;Andregan&quot;
  },
  &quot;county&quot;: {
    &quot;name&quot;: &quot;Silk&quot;,
    &quot;code&quot;: &quot;21&quot;
  },
  &quot;city&quot;: {
    &quot;code&quot;: &quot;44&quot;,
    &quot;name&quot;: &quot;Wrens&quot;
  },
  &quot;rural&quot;: {
    &quot;code&quot;: &quot;49&quot;,
    &quot;name&quot;: &quot;Cardin&quot;
  },
  &quot;canEvaluate&quot;: true
  },
  {
  &quot;index&quot;: &quot;5260680&quot;,
  &quot;studentName&quot;: &quot;MEDIW KENULA&quot;,
  &quot;marks&quot;: &quot;177&quot;,
  &quot;gender&quot;: &quot;M&quot;,
  &quot;resultId&quot;: 18,
  &quot;province&quot;: {
    &quot;code&quot;: &quot;2&quot;,
    &quot;name&quot;: &quot;Kiren&quot;
  },
  &quot;county&quot;: {
    &quot;name&quot;: &quot;Georgia&quot;,
    &quot;code&quot;: &quot;23&quot;
  },
  &quot;city&quot;: {
    &quot;code&quot;: &quot;34&quot;,
    &quot;name&quot;: &quot;Eden Hill&quot;
  },
  &quot;rural&quot;: {
    &quot;code&quot;: &quot;99&quot;,
    &quot;name&quot;: &quot;Southern Sea&quot;
  },
  &quot;canEvaluate&quot;: true
  }
  ]
  </code></pre>
  <p>I want to group this response as <code>province</code> , <code>county</code>, <code>city</code>, <code>rural</code> wise as shown in below rendered <code>antd</code> tree table.</p>
  <p><a href="https://i.stack.imgur.com/4kmSG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4kmSG.png" alt="expected tree table" /></a>.</p>
  <p>To get above tree table and get selected students, I need to format the response as below for the <code>dataSource</code>.</p>
  <p>Expected output is as below.</p>
  <pre><code>const data = [
    {
      key: '1',
      name: 'Andregan',
      resultCount: 3,
      resultIds: [16, 17, 21],
      children: [
        {
          key: '21',
          name: 'Silk',
          resultCount: 2,
          resultIds: [16, 17, 21],
          children: [
            {
              key: '234',
              name: 'Meegan',
              resultCount: 2,
              resultIds: [16, 17],
              children: [
                {
                  key: '41',
                  name: 'Thumphil',
                  resultCount: 2,
                  resultIds: [16, 17],
                },
              ],
            },
            {
              key: '44',
              name: 'Wrens',
              resultCount: 1,
              resultIds: [21],
              children: [
                {
                  key: '49',
                  name: 'Cardin',
                  resultCount: 1,
                  resultIds: [21],
                },
              ],
            },
          ],
        },
      ],
    },
    {
      key: '2',
      name: 'Kiren',
      resultCount: 1,
      resultIds: [18],
      children: [
        {
          key: '23',
          name: 'Georgia',
          resultCount: 1,
          resultIds: [18],
          children: [
            {
              key: '34',
              name: 'Eden Hill',
              resultCount: 1,
              resultIds: [18],
              children: [
                {
                  key: '99',
                  name: 'Southern Sea',
                  resultCount: 1,
                  resultIds: [18],
                },
              ],
            },
          ],
        },
      ],
    },
  ];
  </code></pre>
  <p>Can anyone suggest how to format response to above format to achieve this? Thank you.</p>