时间:2021-07-01 10:21:17 帮助过:8人阅读
核心代码
// var activeSubjectsName = ["语文", "数学", "英语", "思想品德", "科学"]; // 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: "语文", value: 46}, // {name: "数学", value: 2}, // {name: "英语", value: 2}, // {name: "思想品德", value: 28}, // {name: "科学", value: 29} // ]
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
Angular4.x通过路由守卫进行路由重定向步骤详解
jQuery实现模糊查询步骤详解
以上就是js合并数组合生成key:value步骤详解的详细内容,更多请关注Gxl网其它相关文章!