Leaderboard/Score board

Cant say my attempt at array's are the best, but pretty much trying to get like a soccer/sports score board going.
8 teams, first 8 variables for the teams, bottom variables to put the in order, but im lost on how to convert this to rpg maker mv so i can put them in order or howd i get that... lets say variable 467 ended up first and how i would establish that and then the next 7 in order.

var Na = [$gameVariables.value(461), $gameVariables.value(464), $gameVariables.value(467), $gameVariables.value(470), $gameVariables.value(473), $gameVariables.value(476), $gameVariables.value(479), $gameVariables.value(482)];

Na.sort(function(a,d){return a < d});

var variable_names = {};

for(var i = 0; i< Na.length; i++){

variable_names['na_'+i] = Na;

}

//console.log(variable_names);

$gameVariables.setValue(397, variable_names.na_0);

$gameVariables.setValue(398, variable_names.na_1);

$gameVariables.setValue(399, variable_names.na_2);

$gameVariables.setValue(400, variable_names.na_3);


Thanks
Where exactly are you lost? It's pretty much right so far.

variable_names['na_'+i] = Na;

This line doesn't look right, you are setting each property of the object as the entire array (instead of a single value of the array).

Is there a reason that you are converting the sorted array data into an object rather than leaving it as an array?
Yea i was doing that because i was tryinf to find the easiest way to pull up every result so i couod set as another variable. Then hit another hurdle and my brain just melted on what i was trying to accomplish lol
No problem haha, I have been in the 'brain melted' mode many times myself.

I was wondering because objects can be very useful to hold the data if it is complex/different kinds of data. Like if you wanted an object for the whole scoreboard with all the top 8 teams & the top 3 keepers & top 3 goal scorers & last year's champion & location of the match, etc. etc.
I think you get my meaning of how an object can be useful for more complex data maintenance.

Here's the slight edit which should get your original code working.
Code:
var Na = [$gameVariables.value(461), $gameVariables.value(464), $gameVariables.value(467), $gameVariables.value(470), $gameVariables.value(473), $gameVariables.value(476), $gameVariables.value(479), $gameVariables.value(482)];
Na.sort(function(a,d){return a < d});
var variable_names = {};
for(var i = 0; i< Na.length; i++){
    variable_names['na_'+i] = Na[i];
}
//console.log(variable_names);
$gameVariables.setValue(397, variable_names.na_0);
$gameVariables.setValue(398, variable_names.na_1);
$gameVariables.setValue(399, variable_names.na_2);
$gameVariables.setValue(400, variable_names.na_3);

If you don't need the complexity of the object, then you could leave it as an array. The bottom part would just be:

Code:
$gameVariables.setValue(397, Na[0]);
$gameVariables.setValue(398, Na[1]);
$gameVariables.setValue(399, Na[2]);
$gameVariables.setValue(400, Na[3]);

Original thread: https://forums.rpgmakerweb.com/threads/leaderboard-score-board.89340/