[英]How to merge these complex JavaScript array objects?
Can someone help me to do these example? 有人可以帮我做这些例子吗?
var a = ["17","18"];
var b = ["1","1","1"];
I need an output below: 我需要以下输出:
var c = [17:111,18:111]
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]); }
You can join the values of b
together, then use map to create a new array from the indices of a
: 你可以加入的值b
一起,然后用地图来创建的索引一个新的数组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"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.