I am looking to do something very similar to the following PHP code but in javascipt:
for ($weenumber = 1; $weenumber <= 30; $weenumber++)
{
$weenumber = str_pad($weenumber, 2, "0", STR_PAD_LEFT);
echo $_POST["entry{$weenumber}_cash"];
}
Basically accessing the loop number padded with a trailing 0 if less than 10 but I dont know the syntax in JS to do this 🙁
Sorry for noob style question
I think that you mean a leading zero rather than a trailing zero…
You can for example use the conditional operator:
You could also implement a general purpose function:
To access an object property by name in Javascript you use brackets. Example:
If
ncontains4, this will be the same asobj.entry04_cash.