[英]Join two array with same index
i have a problem about how to joining two arrays like this? 我有一个关于如何加入这样的两个数组的问题?
var arrayA = [a,b,c,d,e]
var arrayB = [1,2,3,4,5]
result : [ [a,1], [b,2], [c,3], [d,4], [e,5] ]
(In angularjs) (在angularjs中)
You could try below 您可以在下面尝试
var arrayA = [a,b,c,d,e],
arrayB = [1,2,3,4,5]
var output = arrayA.map(function(value, index){
return [ value, arrayB[index]]
})
console.log(output);
OR you could go for library such as underscore.js . 或者,您可以使用诸如underscore.js之类的库。
Maybe not using angular just Js 也许不使用角度只是Js
var arrayA = [a,b,c,d,e];
var arrayB = [1,2,3,4,5];
var result=[];
for(i=0;i<arrayB.length;i++){
result.push([arrayA[i],arrayB[i]]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.