Actually you just want to write the data to the array.
So you need a two dimensional array.
Next you can write or read the values to and from the array.
class player {
constructor(name, val, ...) {
this.name = name;
this.val = val; // ....
}
toarr()
{
arr=[];
arr[0] = this.name;
arr[1] = this.val; //etcetera
return arr;
}
fromarr(arr){
this.name = arr[0];
this.val = arr[1]
...
}
}
actually you need just one instance of player, and reset the values everytime to access or create other players.
reset( name, val){
this.name = name;
this.val = val; // ....}
so, code equal to the constructor.
eventually the array of all players will look somewhat like this:
players = [];
current_player = new player (name, val);
players[0] = current_player.toarr();
current_player.reset(name1, val1);
players[1] = current_player.toarr();
or
current_player.fromarr[24];
(note you could also write code like current_player.byname(name))
If you want to compare two players, or all players, you just need two instances of player.
When writing to a two dimensional array, you can use named values. I like it this way.
const NAME = 0;
const VAL = 1;
etcetera
You can easily add a value to the array, by adding a val2 (weight, length, income, likes) You can even add names_of_children; an array within the 2 dimensional array. But this might cause some problems.
To compare players, or to sort players, you could also just access the array.
If you write all code in a seperated file, and this file is only loaded if you access and manipulate data of the players, you do not have to make a class of het array, it could as well be a module.
if (we_use_the_players_array === true) {do load the players.js file}
refreshing the whole page, so other ... .js files are not used