How to increment number to a variable in JS?

0

I want to know how to increment a number to a variable in JS every time it goes through the while loop. For example:

var num2 = 1;

while(num2 < num){
    new google.maps.Marker({
        position: posicao(incrementar valor de num2 aqui),
        title: nome(incrementar valor de num2 aqui),
        map: map
    });

    num2++;
}
    
asked by anonymous 22.06.2018 / 14:12

1 answer

2

You can do this by creating 2 variables by concatenating the variable:

var num2 = 1;

while(num2 < num){

   var posicao = "posicao"+num2;
   var nome = "nome"+num2;

    new google.maps.Marker({
        position: posicao,
        title: nome,
        map: map
    });

    num2++;
}
    
22.06.2018 / 14:59