This time I will bring you js mergingArray Detailed explanation of the steps of combining to generate key: value, js merging array to generate key:valueWhat are the precautions, the following is a practical case , let’s take a look.
Core Code
// 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} // ]
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Angular4.x Detailed explanation of route redirection steps through route guards
jQuery implementation of fuzzy query steps Detailed explanation
The above is the detailed content of js combines arrays to generate key: detailed explanation of value steps. For more information, please follow other related articles on the PHP Chinese website!