富贵资源网 Design By www.hznty.com

核心代码

// 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}
// ]

原理就是将两个数组结合到一个数组里面,跟json对照关系一样,需要的朋友可以参考一下,注意两个数组按顺序对应好即可。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com