我需要对值 miles
进行排序和price
基于perMile
.
objs[i] = [
{
miles : array[i].value1
},
{
price: array[i].value2
},
{
perMile: array[i].value3
}
];
我是 JavaScript 新手
最佳答案
我建议
objs[i] = {
miles : array[i].value1,
price: array[i].value2,
perMile: array[i].value3
};
然后,您可以按照项目的 perMile
属性对 objs
数组进行排序(假设它们是数字):
objs.sort(function(a, b) {
return a.perMile - b.perMile;
});
关于Javascript-关联数组排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18052986/