如何按键过滤数组?



我需要由庄家筛选数组。键=== 'bovada'。我需要这方面的数据。这个问题对我研究数组很重要。

const array = [
{
"id": "9ee1340b779938f9a7f829f22d41534d",
"sport_key": "soccer_argentina_primera_division",
"sport_title": "Primera División - Argentina",
"commence_time": "2023-03-30T23:00:00Z",
"home_team": "Defensa y Justicia",
"away_team": "Velez Sarsfield BA",
"bookmakers": [
{
"key": "foxbet",
"title": "FOX Bet",
"last_update": "2023-03-30T14:01:13Z",
"markets": [
{
"key": "h2h",
"last_update": "2023-03-30T14:01:13Z",
"outcomes": [
{
"name": "Argentinos Juniors",
"price": 1.74
},
{
"name": "Godoy Cruz",
"price": 5.4
},
{
"name": "Draw",
"price": 3.25
}
]
}
]
},
{
"key": "bovada",
"title": "Bovada",
"last_update": "2023-03-30T13:58:23Z",
"markets": [
{
"key": "h2h",
"last_update": "2023-03-30T13:58:23Z",
"outcomes": [
{
"name": "Argentinos Juniors",
"price": 1.74
},
{
"name": "Godoy Cruz",
"price": 5.4
},
{
"name": "Draw",
"price": 3.25
}
]
}
]
}
]
},
{
"id": "6253cf45de6b5050c44505812e12f5fd",
"sport_key": "soccer_argentina_primera_division",
"sport_title": "Primera División - Argentina",
"commence_time": "2023-03-31T00:30:00Z",
"home_team": "Argentinos Juniors",
"away_team": "Godoy Cruz",
"bookmakers": [
{
"key": "foxbet",
"title": "FOX Bet",
"last_update": "2023-03-30T14:01:13Z",
"markets": [
{
"key": "h2h",
"last_update": "2023-03-30T14:01:13Z",
"outcomes": [
{
"name": "Argentinos Juniors",
"price": 1.74
},
{
"name": "Godoy Cruz",
"price": 5.4
},
{
"name": "Draw",
"price": 3.25
}
]
}
]
},
{
"key": "bovada",
"title": "Bovada",
"last_update": "2023-03-30T13:58:23Z",
"markets": [
{
"key": "h2h",
"last_update": "2023-03-30T13:58:23Z",
"outcomes": [
{
"name": "Argentinos Juniors",
"price": 1.74
},
{
"name": "Godoy Cruz",
"price": 5.4
},
{
"name": "Draw",
"price": 3.25
}
]
},
{
"key": "spreads",
"last_update": "2023-03-30T13:58:23Z",
"outcomes": [
{
"name": "Argentinos Juniors",
"price": 1.95,
"point": -0.75
},
{
"name": "Godoy Cruz",
"price": 1.87,
"point": 0.75
}
]
}
]
}
]
},
]

我期望得到没有foxbet信息的数组。我只能过滤简单数组。我已经两天不能过滤这个数组了…

I tried array。过滤器(i =比;i.bookmakers。过滤器(k =比;K.key == "bovada"))但是,没有

const result = array.filter((arr) => {
let newBookmaker = arr.bookmakers.filter(
(bookmaker) => bookmaker.key == "bovada"
);
if (newBookmaker.length > 0) {
arr.bookmakers = newBookmaker;
return arr;
}
});

相关内容

  • 没有找到相关文章

最新更新