Lenny Magico Lenny Magico - 11 months ago 43
Javascript Question

How do I combine 2 javascript variables into a string

I would like to join a js variable together with another to create another variable name... so it would be look like;

for (i=1;i<=2;i++){
var marker = new google.maps.Marker({
map: map,
icon: "image"+i

and later on I have


Answer Source

Use the concatenation operator +, and the fact that numeric types will convert automatically into strings:

var a = 1;
var b = "bob";
var c = b + a;