I am trying to create a new key-value or associative array "gradepoints" using two old arrays "grades" and "array". I tried with and without curly braces in the loop.
我正在尝试使用两个旧的数组“grade”和“array”创建一个新的键值或关联数组“gradepoints”。我在循环中尝试使用和不使用花括号。
var gradepoints = [];
for(var i=0; i<array.length; i++) {
gradepoints[i] = {array[i] : grades[array[i]] };
}
1 个解决方案
#1
1
var gradepoints = {};
for(var i=0; i<array.length; i++) {
gradepoints[array[i]] = grades[array[i]];
}
#1
1
var gradepoints = {};
for(var i=0; i<array.length; i++) {
gradepoints[array[i]] = grades[array[i]];
}