For example, how can I turn the array of objects shown below into the corresponding result where names are grouped by id? I'd like to do this using vanilla Javascript and without using an external library like lodash if possible.
Example array:
const items = [
{ id: 1, name: 'a' },
{ id: 2, name: 'b' },
{ id: 3, name: 'c' },
{ id: 1, name: 'd' },
{ id: 3, name: 'f' },
{ id: 1, name: 'a' },
{ id: 3, name: 'c' },
];
Expected result:
const result = [
{ id: 1, names: ['a', 'd']},
{ id: 2, names: ['b']},
{ id: 3, names: ['c', 'f']}
]