Here is a JSON dataset I am working with:
[
{
"campaignId": 111,
"campaignCategory": "Diabetes",
"result": [
{
"campaignType": 1,
"name": "tes1"
},
{
"campaignType": 1,
"name": "test22"
},
{
"campaignType": 3,
"name": "test33"
}
]
},
{
"campaignId": 222,
"campaignCategory": "Orthopedic",
"result": [
{
"campaignType": 1,
"name": "Orthopedic"
}
]
},
{
"campaignId": 333,
"campaignCategory": "Cardiology",
"result": [
{
"campaignType": 3,
"name": "Cardiology"
},
{
"campaignType": 1,
"name": "Cardiology 123"
}
]
}
]
I tried the following filter but it did not return the desired data:
_.filter(summary, function (data) {
return (post, _.filter(data.result, {'campaignType': 3}));
I am looking to obtain the following data after applying the filter:
[{ campaignId: 111, campaignCategory: 'Diabetes', result: [{
campaignType: 3, name: 'test33'
}] },
{ campaignId: 333, campaignCategory: 'Cardiology', result: [{
campaignType: 3, name: 'Cardiology'
}] } ];
Only nodes with campaignType: 3
are displayed in the filtered result.
Either a Lodash or pure JavaScript solution will be suitable.