I have this code. :
$.getJson('api/players_.json', function(players){
// ... some logic code stuff to generate a custom parent object
// with 20 teams of 11 players
$.each(chosenSetupPerTeam, function(i){
console.log(chosenSetupPerTeam[i]);
$.each(chosenSetupPerTeam[i], function(n){
console.log(chosenSetupPerTeam[i][n].player_surname +' '+chosenSetupPerTeam[i][n].role_name +' '+chosenSetupPerTeam[i][n].team_name);
});
});
I'm implementing an array iteration inside a $.getJSON call to append some elements to the DOM.
It's working fine, but I need to order the results of the iteration with a criterio.
Here is the console log, I want to sort the players by role
example: Portiere, Difensore, Centrocampista, Attaccante.
I also want to ask if for a nested object example: array(20) that contains array(11), is a better method to iterate over?
Extension Started!
team.min.js:1 Array(11)
team.min.js:1 Mazzitelli Centrocampista Sassuolo
team.min.js:1 Gravillon Difensore Sassuolo
team.min.js:1 Pegolo Portiere Sassuolo
team.min.js:1 Traoré Centrocampista Sassuolo
team.min.js:1 Matri Attaccante Sassuolo
team.min.js:1 Babacar Attaccante Sassuolo
team.min.js:1 Muldur Difensore Sassuolo
team.min.js:1 Goldaniga Difensore Sassuolo
team.min.js:1 Peluso Difensore Sassuolo
team.min.js:1 Magnanelli Centrocampista Sassuolo
team.min.js:1 Obiang Centrocampista Sassuolo
Can anyone guide me?