在JavaScript中组合2个变量

时间:2014-10-03 22:35:39

标签: javascript arrays

如何组合2个变量torso和comb来正确访问数组中的字符串

var comb = new Array("MT 1.1","MT 1.2","MT 1.3","MT 1.4","MT 1.5","MT 1.6","MT 1.7","MT 1.8","MT 1.9","MT 2","MT 2.1","MT 2.2");

var torso = 2;
var num = comb[+torso+];

1 个答案:

答案 0 :(得分:3)

使用torso变量作为索引来访问comb数组中的项目:

var num = comb[torso];

2的值为torsonum将包含数组中的第三项; "MT 1.3"