Ankit Ahuja
Ankit Ahuja

Reputation: 73

naming objects using for loop

is there a way to name a series of objects like so:

for (i=0; i<numberOfObjectsDesired; i++;) {
    Object ("thisone"+i);
    thisone+i = new Object();
}

such that thisone0, thisone1, thisone2, thisone3, ... etc are all unique instances of Objects

Upvotes: 0

Views: 46

Answers (1)

Heinzi
Heinzi

Reputation: 172270

Sure, it's called an array:

var thisone = new object[numberOfObjectsDesired];

for (i=0; i<numberOfObjectsDesired; i++;) {
    Object ("thisone"+i);
    thisone[i] = new Object();
}

Just note that you have to refer to your instances as thisone[0], thisone[1], etc. instead of thisone0, thisone1, ...

Upvotes: 2

Related Questions