js合并数组合生成key:value步骤详解
程序员文章站
2022-04-30 08:24:41
...
这次给大家带来js合并数组合生成key:value步骤详解,js合并数组合生成key:value的注意事项有哪些,下面就是实战案例,一起来看一下。
核心代码
// 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} // ]
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
以上就是js合并数组合生成key:value步骤详解的详细内容,更多请关注其它相关文章!
上一篇: async/await地狱问题处理
下一篇: linux学习笔记之统计