Skip to content
← Back to Community
[JS] Is there anyway to make this code smaller but have the same function?
Profile icon
MisledWater79
try { txt += ' --'+data_users[0]+': '+data_num_money[0]+'-- \n'; try { txt += ' --'+data_users[1]+': '+data_num_money[1]+'-- \n'; try { txt += ' --'+data_users[2]+': '+data_num_money[2]+'-- \n'; try { txt += ' --'+data_users[3]+': '+data_num_money[3]+'-- \n'; try { txt += ' --'+data_users[4]+': '+data_num_money[4]+'-- \n'; } catch (e){}; } catch (e){}; } catch (e){}; } catch (e){}; } catch (e){};
Voters
Profile icon
MisledWater79
Comments
hotnewtop
Profile icon
AzureDev
if (data_users[4] !== undefined) const max = 4; else if (data_users[3] !== undefined) const max = 3; else if (data_users[2] !== undefined) const max = 2; else if (data_users[1] !== undefined) const max = 1; else if (data_users[0] !== undefined) const max = 0; else const max = -1; for (let i = 0; i <= max; i++) { txt += ' --' + data_users[i] + ": " + //etc. }
Profile icon
MisledWater79