Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11601

Sort a JSON data by specific ID to be on head of result

$
0
0

I have a JSON data for API to display list of marches of different league referenced by ID like that:

var data  = [{"league": {"id": 722,"name": "Liga Premier Serie A","country": "Mexico","logo": "https://media.api-sports.io/football/leagues/722.png","flag": "https://media.api-sports.io/flags/mx.svg","season": 2023,"round": "Group 2 - 19"},"teams": [    {"home": {"id": 17787,"name": "Lobos ULMX","logo": "https://media.api-sports.io/football/teams/17787.png","winner": null   ..... "score": [    {"halftime": {"home": 1,"away": 1        },"fulltime": {"home": 3,"away": 2        },"extratime": {"home": null,"away": null        },"penalty": {"home": null,"away": null        }    },....."league": {"id": 872,"name": "Liga Premier Serie B","country": "Mexico","logo": "https://media.api-sports.io/football/leagues/872.png","flag": "https://media.api-sports.io/flags/mx.svg","season": 2023,....]

I am trying to sort this data by some specific League ID first to be on the head of search, something like that var leagueId = [6,1,44,567,...]:

 for(var i=0;i<data.length;i++) {  if(data[i].teams.league.id == leagueId[key]) {  data.sort((a, b) => (b ....// here get the new JSON data with interested League to be on the head of result  } }

Any idea?


Viewing all articles
Browse latest Browse all 11601

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>