I'm using an API to display stats of footballers, Using Javascript, I've currently got a 'for Loop' that goes through all of the players and displays them in a table.
What I'm looking to do is now find and display the players with the top stats - top scorers/most clean sheets/most red cards etc. How do I go about doing this?
Here's a sample of relevant JSON data from the API:
{
"elements": [
{
"first_name": "Petr",
"second_name": "Cech",
"minutes": 585,
"goals_scored": 0,
"assists": 0,
"clean_sheets": 1,
},
{
"first_name": "Bernd",
"second_name": "Leno",
"minutes": 135,
"goals_scored": 0,
"assists": 0,
"clean_sheets": 0,
},
{
"first_name": "Mesut",
"second_name": "Özil",
"minutes": 510,
"goals_scored": 2,
"assists": 0,
"clean_sheets": 2,
},
*(and on and on...)*
]}
There are around 500 players in this, so I need to have something that will go through all of them and work out which players have the highest values for each property name.
How can I get it so that I can (for example) show the top scorer, their goals and name. I'm not sure on the correct way to do this, whether it's to for loop through again and somehow do something with math.max?
Thanks!