Petro Adamovich
Petro Adamovich

Reputation: 41

How do you create objects using a for loop

I know this is probably really difficult, because I want something like Object1, Object2, etc. This is what I think might work, but probably won't.

for(var x = 1; x<=10; x++){
    var Object + x = new Object();
};

What should I do instead. Thanks in advance!

Upvotes: 1

Views: 56

Answers (1)

Ferrakkem Bhuiyan
Ferrakkem Bhuiyan

Reputation: 2783

var objects = {};

for (var x = 0; x < 100; x++) {
  objects[x] = {name: "value"};  //value can be a string like "value" or a var like value 
}

Upvotes: 2

Related Questions