I am facing a challenge with filtering objects in an array. Each object contains a title and rows, where the rows also have a risk value (like P1, P2, P3, etc.). My goal is to extract only the rows that have a risk equal to P1 while skipping any objects that do not contain any P1 risks.
let data = [
{
"title": "QA",
"rows": [
{
"risk": "P3",
"Title": "Permission issue",
}
]
},
{
"title": "Prod",
"rows": [
{
"risk": "P5",
"Title": "Console log errors fix",
},
{
"risk": "P1",
"Title": "Server is in hung state",
}
]
}
]
The desired result should look like this:
{
"title": "Prod",
"rows": [
{
"risk": "P1",
"Title": "Server is in hung state",
}
]
}
]
Currently, the code I tried includes titles even if they do not have any P1 risks. Can someone provide a solution to filter out objects without P1 risks entirely?