如何将2个javascript变量组合成一个字符串 [英] How do I combine 2 javascript variables into a string

查看:311
本文介绍了如何将2个javascript变量组合成一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加入一个js变量和另一个来创建另一个变量名...所以它看起来像;

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({
position:"myLatlng"+i,
map: map, 
title:"title"+i,
icon: "image"+i
}); 
}

以及稍后我有

myLatlng1=xxxxx;
myLatlng2=xxxxx;


推荐答案

使用连接运算符 + ,以及数字类型将转换的事实自动转换为字符串:

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;

这篇关于如何将2个javascript变量组合成一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆