我想为此创建一个未排序的 JavaScript 数组对象,我有两个数组
var degree_values = ['Bachelors', 'Doctoral / PhD', 'Masters', 'MBA', 'Professional Certifications'];
var degree_indexes = ["4", "3", "2", "1", "5"];
var values = {};
for(var index in degree_values){
values[degree_indexes[index]] = degree_values[index];
}
console.log(values);
输出为
Object { 1="MBA", 2="Masters", 3="Doctoral / PhD", 4 = 'MBA', 5 = 'Professional Certifications'}
预期输出是
Object { 4 = 'MBA', 3="Doctoral / PhD", 2="Masters", 1="MBA", 5 = 'Professional Certifications'}
最佳答案
轻松使用开源项目jinqJs
var degree_values = ['Bachelors', 'Doctoral / PhD', 'Masters', 'MBA', 'Professional Certifications'];
var degree_indexes = ["4", "3", "2", "1", "5"];
//Gets emails that are in current not in group
var result = jinqJs().from(degree_values).select(function(row,index){
var obj = {};
obj[degree_indexes[index]] = row;
return obj;
});
关于javascript - 创建 Javascript 未排序数组对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29430353/