How do I combine 2 javascript variables into a string

后端 未结 5 889
有刺的猬
有刺的猬 2020-12-03 03:40

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 =         


        
5条回答
  •  甜味超标
    2020-12-03 03:53

    You can use the JavaScript String concat() Method,

    var str1 = "Hello ";
    var str2 = "world!";
    var res = str1.concat(str2); //will return "Hello world!"
    

    Its syntax is:

    string.concat(string1, string2, ..., stringX)
    

提交回复
热议问题