I have an array of objects that looks like this:
[
{
"id": "5eece32be3a4f43ca8e98688",
"title": "Main",
"children": [
{
"id": "5eece339e3a4f43ca8e98689",
"title": "Child"
}
]
},
{
"id": "5eece354e3a4f43ca8e9868a",
"title": "Another",
"children": [
{
"id": "5eece362e3a4f43ca8e9868b",
"title": "Child 2",
"children": [
{
"id": "5eece36ee3a4f43ca8e9868c",
"title": "Child 3"
}
]
},
{
"id": "5eece9210a445e2d0ca78978",
"title": "Temp"
}
]
}
]
I need to pull the id from each main object and child object. There can be any number of nested children; it can go down multiple levels so this needs to be able to adapt to however many children an object has. I tried mapping it and pulling the id to a new array but that only gives me the 2 main objects. Is there a way to do this where it creates an array with all id's.
Something like this:
["5eece32be3a4f43ca8e98688", "5eece339e3a4f43ca8e98689", "5eece354e3a4f43ca8e9868a", "5eece362e3a4f43ca8e9868b", "5eece36ee3a4f43ca8e9868c", "5eece9210a445e2d0ca78978"]