核心代码
// 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} // ]
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
angular4.x通过路由守卫进行路由重定向步骤详解
jquery实现模糊查询步骤详解
以上就是js合并数组合生成key:value步骤详解的详细内容。
