I am finding difficulty in filtering an nested array of object. Can someone please let me know where i am going wrong.
Here is the data and i want to filter out all objects which has risk P1
{
"title": "QA",
"rows": [
{
"risk": "P1",
"Title": "Server down",
},
{
"risk": "P3",
"Title": "Permission issue",
}
]
},
{
"title": "Prod",
"rows": [
{
"risk": "P5",
"Title": "Console log errors fix",
},
{
"risk": "P1",
"Title": "Server is in hung state",
}
]
}
]
I want the result as follows
[
{
"title": "QA",
"rows": [
{
"risk": "P1",
"Title": "Server down",
}
]
},
{
"title": "Prod",
"rows": [
{
"risk": "P1",
"Title": "Server is in hung state",
}
]
}
]
In order to achieve this, i tried this way but unable to get desired result. Can someone please let me know where i go wrong
data.forEach((element, index) => {
return element.rows.filter( x => x.risk === 'P1' )
});