I have an array with objects, that can have children, the children have the same structure as the parent, it's just object nesting basically.
I'm wondering how I can flatten the structure of my objects so I have the id's of all the objects, including the nested one's.
For example, This structure
const data = [
{
id: 2,
children: [
{
id: 1,
children: []
}
]
},
{
id: 3,
children: [],
}
]
Should be flattened to this
const data = [2,1,3]
I've tried
Using Array.reduce() and the object spread syntax, but I can't wrap my head around the logic required to do this.