In my web-based game, I use the forEach command to retrieve the team players in the lobby. However, for a specific feature in my game, I need to extract the id of the first player from the opposing team. How can I modify my current code to achieve this?
The following code currently retrieves the ids of all players on the opposing team. What I am looking for is the id of only the first player on the opposing team. I hope this clarifies what I am trying to accomplish.
lobby.players
.filter((player) => player.team !== team)
.forEach((player) => {
socketServer.to(player.id).emit('GameRound', Role.Watcher);
});