How to change an object of objects into object of arrays of objects. As below. I have included the output and the result. I’m interested in every way to do this, but I’m particularly interested in exploring reduce method. Because I guess it’s possible in this case?
I know how convert an array to an object with array.reduce() but not this one.
So, how to change this one:
const sourceData = {
0: {
name: "Mario",
game: {
home: "Nintendo",
console: "Nintendo Switch",
playground: "Mario Kart",
},
},
1: {
name: "Yoshi",
game: {
home: "Nintendo",
console: "Nintendo Switch",
playground: "Mario Kart",
},
},
2: {
name: "Aya Brea",
game: {
home: "Sony",
console: "PlayStation",
playground: "Parasite Eve",
},
},
3: {
name: " Solid Snake",
game: {
home: "Sony",
console: "PlayStation",
playground: "Metal Gear",
},
},
};
into this one:
const resultingData = {
Nintendo: [
{
name: "Mario",
game: {
home: "Nintendo",
console: "Nintendo Switch",
playground: "Mario Kart",
},
},
{
name: "Yoshi",
game: {
home: "Nintendo",
console: "Nintendo Switch",
playground: "Mario Kart",
},
},
],
Sony: [
{
name: "Aya Brea",
game: {
home: "Sony",
console: "PlayStation",
playground: "Parasite Eve",
},
},
{
name: "Solid Snake",
game: {
home: "Sony",
console: "PlayStation",
playground: "Metal Gear",
},
},
],
};