Which is better for performance - having a lookup function that finds an object in array with a particular ID or just using for in loop with holes in array?
In my situation I've got players array which is dynamic. Let's say 3 players are connected so my array would look like this:
players = [player1, player2, player3]
It would be easy to keep array key as player ID so I would know that player with ID 2 is 3rd in players array and in order to access him I just need to use: players[2]
but as the 2nd player leaves he creates an array hole:
players = [player1,,player3]
And as I understand this hole reduces the performance of using array, since I'm using for-in loop a lot, would it be a better to have an array of player objects and instead of leaving array holes I just splice the hole out? But this way I wouldn't be able to keep array key as player ID so I would have to use ID lookup function. So in the end which one of these 2 choices is better for performance? Or there is even better way to fix this issue?
Thank You!