I have this array of objects
[
  { id: '1', foo: 'bar' },
  { id: '1', foo: 'foo' },
  { id: '4', bar: 'foo' }
]
How could I merged it by id to get result below?
Desired result:
{
  '1': [
    { foo: 'bar' },
    { foo: 'foo' }
  ]
  '4': [
    { bar: 'foo' }
  ]
}
I tried Object.entries but this method won't work for what I'm doing.
Edit:
I read answers to this question and first of all none of them fully answers my question and second they are also no typescript answers.
All answers there was key => val while I need key => array of objects of that key
 
     
     
    