我有一個(gè)從 sql 查詢中獲得的對(duì)象,我想刪除其中的一個(gè)項(xiàng)目。問題是,在我刪除它之后,該項(xiàng)目沒有任何信息,但它仍然存在:<1 empty item>所以我想知道是否有辦法完全刪除它并擁有一個(gè)只有我的數(shù)據(jù)的干凈對(duì)象?!贝a是在數(shù)據(jù)庫(kù)中的兩個(gè)玩家之間建立匹配并且它曾經(jīng)有效但我必須驗(yàn)證選定的玩家不是被排除在外的人,因?yàn)樗麄兒芷婀?,我想隨機(jī)排除一個(gè)。所以我意識(shí)到簡(jiǎn)單地從對(duì)象中刪除不打算參加比賽的玩家要容易得多.我會(huì)留下孔碼。 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); }希望我能夠解釋我自己。感謝您的幫助。
從 Javascript 對(duì)象中刪除項(xiàng)目
一只名叫tom的貓
2023-04-20 10:16:30