How to convert an object of objects (initial form of object) into object of arrays of objects (target form of object)
I am interested in every way to do this, but I am particularly interested in exploring reduce method. Because I guess it is possible in this case? I know how to convert an array to an object using array.reduce () but not such a transformation as below.
So, I don't know how to convert an object with objects (initial form of object) to an object of arrays of objects (target form of object)
So, how to change this one:
Starting situation: (initial form of object)
const beforeConversion = {
0: {
name: "Mario",
game: {
home: "Nintendo",
playground: "Mario Kart",
},
},
1: {
name: "Yoshi",
game: {
home: "Nintendo",
playground: "Mario Kart",
},
},
2: {
name: "Aya Brea",
game: {
home: "Sony",
playground: "Parasite Eve",
},
},
3: {
name: "Solid Snake",
game: {
home: "Sony",
playground: "Metal Gear",
},
},
into this one:
Expected result: (target form of object)
const afterConversion = {
Nintendo: [
{
name: "Mario",
game: {
home: "Nintendo",
playground: "Mario Kart",
},
},
{
name: "Yoshi",
game: {
home: "Nintendo",
playground: "Mario Kart",
},
},
],
Sony: [
{
name: "Aya Brea",
game: {
home: "Sony",
playground: "Parasite Eve",
},
},
{
name: "Solid Snake",
game: {
home: "Sony",
playground: "Metal Gear",
},
},
],
};
0 Comment(s)