I'm currently dealing with a JSON/JavaScript structure that looks like this:
{
"comments": [
{
"id": 1,
"content": "lorem ipsum",
"answers": []
},
{
"id": 2,
"content": "lorem ipsum",
"answers": [
{
"id": 30,
"content": "lorem ipsum"
}
]
},
{
"id": 3,
"content": "lorem ipsum",
"answers": [
{
"id": 99,
"content": "lorem ipsum"
},
{
"id": 103,
"content": "lorem ipsum"
}
]
},
{
"id": 5,
"content": "comment",
"answers": []
}
]
}
My goal is to create an array that includes the id of all comments, regardless of whether they are main comments or answers.
The final array should look like this:
[1, 2, 3, 5, 30, 99, 103]
Is it possible to achieve this using only map
, reduce
, and filter
?
What other approaches could I consider?