I've got an object that I get from a sql query and I want to delete an item inside of it. The thing is that after I delete it, that item has no information but it's still there as:
<1 empty item>
so I would like to know if there is a way to completely remove it and have a clean object with only my data." The code is to establish matches between two players from the database and it used to work but I would have to verify that the selected player was not the one being left out since they are odd and I wanted a random one to be left out. So I realized it was way easier to simply remove the player that is not going to take part in the matches from the object. I will leave the hole code.
let tournamentID = args[0];
let categoryID = args[1];
let tournamentSQL = 'SELECT * FROM tournaments WHERE tournamentID = ?';
let tournamentData = [tournamentID];
let matchesCreated = 0;
con.query(tournamentSQL, tournamentData, function(err, result){
if(err) throw err;
let playersSQL = "SELECT * FROM players WHERE tournamentID = ?";
if(result.length == 0){
return message.channel.send('Ingresaste un TournamentID incorrecto');
};
if (result[0].modality > 1){
return message.channel.send('Este torneo es por equipos, usa .partidosequipos');
};
let actualRound = result[0].actualRound + 1;
con.query(playersSQL, tournamentData, function(err, resultPlayers){
if(resultPlayers.length == 0){
return message.channel.send('Este torneo no tiene jugadores.');
};
if(err) throw err;
let roundPlayers = resultPlayers.length - 1;
if(resultPlayers.length % 2 != 0){
let player = Math.round(Math.random() * roundPlayers);
console.log(player);
message.channel.send(`La cantidad de jugadores en el torneo es impar, el jugador ${resultPlayers[player]} no jugará en esta ronda y ya clasificó a la siguiente`);
delete resultPlayers[player];
matchCreating(roundPlayers, resultPlayers, result, categoryID, client, message, actualRound);
} else{
matchCreating(roundPlayers, resultPlayers, result, categoryID, client, message, actualRound);
}
Hope I was able to explain my self. Thank you for your help.
resultPlayersan array?