I have a collection of different objects stored in an array. Each object within the main array contains another array with specific details like this:
const data =
[
{
id: 1, name: "Jack", interests:
[
{id: 9, name: "basketball"},
{id: 8, name: "art"}
]
},
{
id: 2, name: "Jenny", interests:
[
{id: 7, name: "reading"},
{id: 6, name: "running"}
]
}
];
My goal is to combine all nested arrays into one new array structured like this:
newArray =
[
[{id: 9, name: "basketball"}, {id: 8, name: "art"}],
[{id: 7, name: "reading"},{id: 6, name: "running"}]
];
Even though I tried pushing the data to a new array, it becomes unnested when executed like this:
data.map(v => { v.interests.map(x => { newArray.push({name: x.name, id:x.id}) }) })
Is there a way I can transfer the nested structure of the interests data to the new array?