Philipp Bergmann Philipp Bergmann - 1 year ago 46
jQuery Question

How do I create dynamic variable names inside a loop?

I'm working on an ajax google maps script and I need to create dynamic variable names in a for loop.

for (var i = 0; i < coords.length; ++i) {
var marker+i = "some stuff";

What I want to get is:
and so on.
and I guess there is something wrong with

Firebug gives me this:
missing ; before statement

Answer Source

Use an array for this.

var markers = [];
for (var i = 0; i < coords.length; ++i) {
    markers[i] = "some stuff";