Create variables with a loop?
January 25, 2006
/ Filed under: Programming
Let’s say I want to quickly create five new variables. It doesn’t matter what programming language we use. Let’s use JavaScript, just for this example. Instead of doing this: var new_variable_1; var new_variable_2; var new_variable_3; var new_variable_4; var new_variable_5; ... I’d like to "group" this better, by doing something like this:
for (i=1; i<6; i++)
{
var new_variable_ + i;
}
See what I’m trying to do? By using the temporary variable The problem is I’m not sure if I can add a variable value to a variable name. Ahhh, only after you spend hours doing this crap, do you come up with such strange concoctions. It’s not even 5 PM, and already I need a beer.
Comments/Mentions
|
Editor Picks
Email NewsletterSubscribe to the digest newsletter to receive posts by email: Recent Comments
Advertisements
|
You should be able to do that. I needed to for one of the java things I was doing.