I am grappling with the challenge of finding a specific object within an array of objects, where the desired object may be nested within another array of one of the objects.
I have experimented with various iterations of forEach loops and recursion methods.
{
"id": 1,
"messages": [{
"id": 4,
"message": "XXXXXXXX",
"code": "XXXXXX",
"subMessages": null
}, {
"id": 8,
"message": "XXXXXXXX",
"code": "XXXXXX",
"subMessages": [{
"id": 9,
"message": "XXXXXXXX",
"code": "XXXXXX",
"subMessages": null
}
]
}, {
"id": 10,
"message": "XXXXXXXX",
"code": "XXXXXX",
"subMessages": [{
"id": 11,
"message": "XXXXXXXX",
"code": "XXXXXX",
"subMessages": [{
"id": 12,
"message": "XXXXXXXX",
"code": "XXXXXX",
"subMessages": null
}
]
}
]
}
]
}
The depth of nesting is uncertain and may exceed that shown in the example, and the arrays may contain multiple messages each. My objective is to locate a message based on its unique ID (IDs are unique across all messages).
Any suggestions?