這次帶給大家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} // ]
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
以上是js合併數組合產生key:value步驟詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!