This question already has answers here:
How to filter object array based on attributes?
                                
                                    (13个回答)
                                
                        
                2年前关闭。
            
        

我有这个:

'{
"Games": [
    {   "champion": 126,
        "season": 9
    },
    {
        "champion": 126,
        "season": 9
    }, {
        "champion": 126,
        "season": 8
    }`


我只想拿第9季以来的冠军号码。我该怎么做?

最佳答案

您可以使用Array.find

const champion = data.Games.find(({season}) => season === 9)


或ES5

var champion = data.Games.find(function(champion) {
   return champion.season === 9;
});

10-07 20:43