JS combines two arrays to generate merged Key: value arrays

 // var ActiveSubjectsName = ["Chinese", "Mathematics", "English", "Thought", "Science"]; // 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}
// ] 
The principle is to The array is combined into an array. Like the JSON control relationship, the friends needed can refer to it, pay attention to the two arrays, according to the order.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment