Currently, I am faced with a situation where I have one array containing 6 category names and 6 arrays of objects, each containing 5 objects related to those categories. I am seeking the most efficient way to restructure these data sets so that I end up with just 6 arrays of objects that combine data from both the category array and the object arrays.
let categoryArray = ["a", "b", "c","d","e","f"];
let outcomeArrays = [
[ {p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null} ],
[ {p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null} ],
[ {p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null} ],
[ {p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null} ],
[ {p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null} ],
[ {p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null} ]
];
My goal is to create an array structured as follows:
[{category: "a",
details: [{p:1,q:2,r:null},{p:3,q:4,r:null},{p:5,q:6,r:null},{p:7,q:8,r:null},{p:9,q:10,r:null}]},
{category: "b",
details: [{p:11,q:22,r:null},{p:33,q:44,r:null},{p:55,q:66,r:null},{p:77,q:88,r:null},{p:9,q:10,r:null}]},
...
]
I attempted using push and map methods, but did not achieve the desired result. I also explored lodash library but could not find a method suitable for handling this scenario.