js合并两个数组生成合并后的key:value数组方法
// var activeSubjectsName = ["JAVA", "PHP", "Android", "IOS", "Python"];
// var activeSubjectsNum = [46, 2, 2, 28, 29];
// var activeSubjectsArr = [];
for (var i = 0; i < activeSubjectsName.length; i++) {
console.log(i);
var activeSubjectsObject = {};
for (var j = 0; j < activeSubjectsNum.length; j++) {
if (i == j) {
activeSubjectsObject.name = activeSubjectsName[i];
activeSubjectsObject.value = activeSubjectsNum[j];
activeSubjectsArr.push(activeSubjectsObject);
}
}
}
console.log(activeSubjectsArr);
// activeSubjectsArr=[
// {name: "JAVA", value: 46},
// {name: "PHP", value: 2},
// {name: "Android", value: 2},
// {name: "IOS", value: 28},
// {name: "Python", value: 29}
// ]
文章评论(0)