I need to obtain the Modules, with those postings whose locality equals to "Vienna", I am not being able to eliminate those that do not pass the validation.
This is the json.
const json = [
{
"title":"Module A",
"postings":[
{"name": "1", "categories":{"location":"Viena"},},
{"name": "2", "categories":{"location":"Paris"},},
{"name": "3", "categories":{"location":"Viena"},},
]
},
{
"title":"Module B",
"postings":[
{"name": "1", "categories":{"location":"Madrid"},},
{"name": "3", "categories":{"location":"Paris"},},
]
},
{
"title":"Module C",
"postings":[
{"name": "1", "categories":{"location":"Madrid"},},
{"name": "2", "categories":{"location":"Viena"},},
]
},
];
Expected result
[
{
"title":"Module A",
"postings":[
{"name": "1", "categories":{"location":"Viena"},},
{"name": "3", "categories":{"location":"Viena"},},
]
},
{
"title":"Module C",
"postings":[
{"name": "2", "categories":{"location":"Viena"},},
]
},
];
This is what I'm trying
const result = json
.filter(module => module.postings
.filter(posting => posting.categories.location === 'Viena').length);
Actual Result
I am not being able to remove those postings that do not meet the condition.