Reactjs React多维数组过滤器/查找

Reactjs React多维数组过滤器/查找,reactjs,react-native,multidimensional-array,filter,Reactjs,React Native,Multidimensional Array,Filter,我有一个多维数组(与玩家的匹配列表),我需要过滤这个数组以只获得唯一的玩家对象 下面的代码可以工作,但我预期的结果不同 Const aPlayer=matchs .filter(match => match.players.find(player => player.id ===id)) 变量aPlayer包含该玩家的所有匹配项 但我只需要玩家对象数据。我不确定你的数据是否是这样结构的: Matches: List<Match> Match: {

我有一个多维数组(与玩家的匹配列表),我需要过滤这个数组以只获得唯一的玩家对象

下面的代码可以工作,但我预期的结果不同

Const aPlayer=matchs
  .filter(match => match.players.find(player => player.id     
 ===id))
变量aPlayer包含该玩家的所有匹配项


但我只需要玩家对象数据。

我不确定你的数据是否是这样结构的:

Matches: List<Match>
Match:   {
    ...,
    players: List<Player>
}
Player: {
   id: Index,
   ...
}
// still contains duplicates, but that's not the issue here
const allPlayers = matchs
    .map(x => x.players)
    .reduce(x => (dest, val) => dest.concat(val), []);

const player = allPlayers.find(x => x.id === id);

不起作用,console.log(allPLayers)=“function(dest,val){return dest.concat(val);}”什么不起作用以及错误/结果是什么?Const allPLayers=matchs.filter(match=>match.players.find(player=>player.id==id))后跟Const player=allPLayers.find(x=>x.id==id);做这项工作,谢谢