有人可以帮助我做这些例子吗?
var a = ["17","18"];
var b = ["1","1","1"];
我需要一个输出:
var c = [17:111,18:111]
答案 0 :(得分:2)
var a = ["17","18"];
var b = ["1","1","1"];
var i=0;
var ConcateC="";
for(i=0;i< b.length;i++)
{
ConcateC +=b[i];
}
var c=[];
for(i=0;i< a.length;i++)
{
c[i]=a[i] + ":" + ConcateC;
alert(c[i]);
}
&#13;
答案 1 :(得分:1)
您可以将b
的值加在一起,然后使用map从a
索引创建一个新数组:
var a = ["17","18"];
var b = ["1","1","1"];
var bValue = b.join("");
var c = a.map(function(currentValue) {
return currentValue + ":" + bValue;
});
console.log(c); // ["17:111","18:111"]