I have the following array of people:
const people = [
{ name: 'Tom Hiddleston', country: 'UK' },
{ name: 'Joe Biden', country: 'USA' },
{ name: 'James Bond', country: 'UK' },
{ name: 'Barack Obama', country: 'USA' },
{ name: 'Dolph Lundgren', country: 'SWEDEN' },
];
Now I want to break this array into multiple arrays based on the country property.
Basically I want a magic function that does the following:
const peopleGroupedByCountry = magicFunction(people);
console.log(peopleGroupedByCountry);
// Should log the following:
[
[
{ name: 'Tom Hiddleston', country: 'UK' },
{ name: 'James Bond', country: 'UK' },
],
[
{ name: 'Joe Biden', country: 'USA' },
{ name: 'Barack Obama', country: 'USA' },
],
[
{ name: 'Dolph Lundgren', country: 'SWEDEN' },
]
]