Answer the question
In order to leave comments, you need to log in
How to implement dynamic addition to an array?
How can this code be simplified?
const savedUser_serverId = saved_user[0].server_id;
servers.push(savedUser_serverId);
switch (savedUser_serverId) {
case 1:
servers.push(2);
servers.push(3);
break;
case 2:
servers.push(1);
servers.push(3);
break;
case 3:
servers.push(1);
servers.push(2);
break;
}
Answer the question
In order to leave comments, you need to log in
servers.push(savedUser_serverId, ...(({
1: [ 2, 3 ],
2: [ 1, 3 ],
3: [ 1, 2 ],
})[savedUser_serverId] ?? []))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question