我有两个这样的数组:
arr1 = ['one','two','three']
arr2 = ['1','2','3']
有没有办法让jQuery组合它们,所以输出就像:
arr3 = ['one':'1', 'two':'2', 'three':'3']
答案 0 :(得分:1)
var result = {};
for(i=0; i< arr1.length && i < arr2.length; ++i){
result[arr1[i]] = arr2[i];
}
答案 1 :(得分:1)
我相信你要求创建一个对象(关联数组),如果是这样的话
var arr1 = ['one','two','three'];
var arr2 = ['1','2','3'];
var combo_obj = {};
arr1.forEach(function(element, index) {
combo_obj[element] = arr2[index];
});
console.log(combo_obj);
这是它的输出
{ one: '1', two: '2', three: '3' }
答案 2 :(得分:0)
是。点击此处:Combaining two array into single multi dimensional array in javascript
以下是一个例子:
arr3=[];
for (i = 0; i < arr2.length; ++i)
{
arr3[i] = Array(arr1[i], arr2[i]);
}