Home > Web Front-end > JS Tutorial > body text

js combines arrays to generate key: detailed explanation of value steps

php中世界最好的语言
Release: 2018-05-22 11:55:21
Original
2341 people have browsed it

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}
// ]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template