Is there a way to extract only the items in the nested arrays that meet a specific criteria or expression?
I've looked at the following links, but the solutions provided do not seem to work with _.filter:
Find object by match property in nested array
lodash property search in array and in nested child arrays
Lodash - Search Nested Array and Return Object
Let me provide more context. I have data structured like this: How can I retrieve the items inside the "listEvents" array for all objects that match a certain criteria?
[
{
"ModalidadeId": 1,
"Nome": "SOCCER",
"Ordem": "09",
"IconeId": "",
"listEvents": [
{
"EI": 2960542,
"No": "SÃO PAULO SP X ATLÉTICO LINENSE-SP",
"St": 1,
"Ini": "2017-09-30T10:00:00",
"MI": 1,
"CI": 251,
"TI": 4993,
"StAV": 0,
"De": false,
"Ics": [
"p22678",
"p22684"
],
"Ic": "",
"Tas": [],
"show": true,
"IniFormatada": "30/09/2017 às 10:00:00",
"MN": "FUTEBOL"
},
...
]
},
{
"ModalidadeId": 2,
"Nome": "TENIS",
"Ordem": "09",
"IconeId": "",
"listEvents": [
{
"EI": 2960542,
"No": "SÃO PAULO SP X ATLÉTICO LINENSE-SP",
"St": 1,
"Ini": "2017-09-30T10:00:00",
"MI": 1,
"CI": 251,
"TI": 4993,
"StAV": 0,
"De": false,
"Ics": [
"p22678",
"p22684"
],
"Ic": "",
"Tas": [],
"show": true,
"IniFormatada": "30/09/2017 às 10:00:00",
"MN": "FUTEBOL"
},
...
]
}
]
This is the code snippet I've attempted, but it doesn't seem to be functioning properly.
_.filter($scope.listModalities, _.flow(
_.property('listEvents'),
_.partialRight(_.filter, function (o) {
var eventDate = new Date(o.Ini);
eventDate.setHours(eventDate.getHours() - 24);
var now = new Date();
return o.De == true || eventDate < now;
})
));