鑑於以下數據如何過濾屬於數組值的對象?
[
{
"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-嵌套值 –