group an array of objects by a property javascript : <p>I have an array of objects. I need to group them by name and then combine another property in an array.</p>

<pre><code>[
   {
      NAME: 'TEST_1',
      ID: '1',
      FROM: '20191223',
      TO: '99991231'
    },

   {
      NAME: 'TEST_1',
      ID: '2',
      FROM: '20191223',
      TO: '99991231'
   },

   {
      NAME: 'TEST_2',
      ID: '3',
      FROM: '20191223',
      TO: '99991231'
   },
   {
      NAME: 'TEST_2',
      ID: '4',
      FROM: '20191223',
      TO: '99991231'
   },
]
</code></pre>

<p>Any my output will be:</p>

<pre><code>[
 {
  NAME: 'TEST_1',
  ID: '[1, 2]',
  FROM: '20191223',
  TO: '99991231'
 },

 {
  NAME: 'TEST_2',
  ID: '[3, 4]',
  FROM: '20191223',
  TO: '99991231'
},
]
</code></pre>
