Is there a more efficient way to handle this code?
At the start of my game, I set up a variable to hold all new game information.
var newGameInfo = {
players: [],
playersList: [],
enemies: [],
enemiesList: [],
drops: [],
dropsList: [],
attacks: [],
attacksList: [],
LVL: null
}
Later on, I clear out this variable by using the following code.
Object.keys(newGameInfo).forEach(key => {
if(Array.isArray(newGameInfo[key])) {
newGameInfo[key] = [];
} else if(typeof newGameInfo[key] === 'number' && key !== 'LVL') {
newGameInfo[key] = 0;
}
});
I would appreciate any tips or suggestions! This code seems overly verbose for such a simple task.