Currently attempting to loop through a nested object.
array=[
{
id: 2,
items: [
{
id: 12
},
{
id: 13
},
{
id: 14
}
]
},
{
id: 3,
items: [
{
id: 15
},
{
id: 16
},
{
id: 17
},
{
id: 18
},
{
id: 19
}
]
},
{
id: 4,
items: [
{
id: 20
},
{
id: 21
}
]
},
{
id: 5,
items: [
{
id: 22
}
]
}
];
The goal is to consolidate all IDs into one array, following the initial data structure. Here's an example of the desired output:
arrayOfId = [2, 12, 13, 14, 3, 15, 16, 17, 18, 19, 4, 20, 21, 5, 22];
I have attempted some solutions with jQuery examples, but my project utilizes Angular. Seeking guidance on achieving this with vanilla JS or Angular specifics.
Appreciate any assistance!