我有两个这样的数组:
arr1 = ['一','二','三']
arr2 = ['1','2','3']
有没有办法用 jQuery 将它们组合起来,这样输出就像:
arr3 = ['一':'1', '二':'2', '三':'3']
最佳答案
如果是这样,我相信你要求创建一个对象(关联数组)
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' }
关于javascript - 组合两个普通数组以创建 key :value pair array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29246150/