鉴于以下数据如何过滤属于数组值的对象?
[
{
"date": "2017-10-04",
"games": [
{
"notes": "Game was played",
"time": "2017-10-04T20:24:30+00:00",
"sport": "hockey",
"owner": "steve",
"players": "10",
"game_id": 1
},
{
"notes": "Game was played",
"time": "2017-10-04T12:35:30+00:00",
"sport": "lacrosse",
"owner": "steve",
"players": "6",
"game_id": 2
},
{
"notes": "Game was played",
"time": "2017-10-04T10:12:30+00:00",
"sport": "hockey",
"owner": "henry",
"players": "10",
"game_id": 4
}
]
},
{
"date": "2017-10-14",
"games": [
{
"notes": "Game was played",
"time": "2017-10-14T20:32:30+00:00",
"sport": "hockey",
"owner": "steve",
"players": "4",
"game_id": 3
},
{
"notes": "Game was played",
"time": "2017-10-14T20:34:30+00:00",
"sport": "soccer",
"owner": "john",
"players": "12",
"game_id": 5
}
]
}
]
我怎么过滤掉的对象,这样我只显示曲棍球比赛于该日播放。本质上我需要相同的对象数组,但只有当游戏键= sport: hockey
只显示对象我知道我只能在数组上运行过滤器方法,但我无法弄清楚如何循环数组内部的对象并再次返回整个对象。任何帮助将不胜感激。
这可能有助于太https://stackoverflow.com/questions/38375646/filtering-array-of-objects-with-arrays-based-嵌套值 –