在Js中,如何将两个list遍历拼接为一个list3=[{a:1},{b:2},{c:3},{d:4}]。
在Js中,如何将两个list:list1=[a,b,c,d];list2=[1,2,3,4],遍历拼接为list3=[{a:1},{b:2},{c:3},{d:4}]?...
在Js中,如何将两个list:list1=[a,b,c,d];list2=[1,2,3,4],遍历拼接为list3=[{a:1},{b:2},{c:3},{d:4}]?
展开
展开全部
function arrcat(arr1,arr2){
if(!Array.isArray(arr1) || !Array.isArray(arr2) || arr1.length != arr2.length) return [];
var arr = [];
for(var i = 0,len = arr1.length;i<len;i++){
var obj = new Object();
obj[arr1[i]] = arr2[i];
arr[i]=obj;
}
return arr;
}
arrcat(["a","b","c","d"],[1,2,3,4]);//结果:[{a:1},{b:2},{c:3},{d:4}]
if(!Array.isArray(arr1) || !Array.isArray(arr2) || arr1.length != arr2.length) return [];
var arr = [];
for(var i = 0,len = arr1.length;i<len;i++){
var obj = new Object();
obj[arr1[i]] = arr2[i];
arr[i]=obj;
}
return arr;
}
arrcat(["a","b","c","d"],[1,2,3,4]);//结果:[{a:1},{b:2},{c:3},{d:4}]
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询