使用sort对数组中的对象的某个属性进行排序

var data=[
{
code: "10004",
grade: "5.6",
planQuantity: 220,
},
{
code: "10024",
grade: "5.6",
planQuantity: 200,
},
{
code: "10034",
grade: "6.6",
planQuantity: 210,
}
];
function orderSort(obj1,obj2){
var a=obj1.planQuantity;
var b=obj2.planQuantity;
if(a>b){
return -1
}else if(a<b){
return 1
}else{
return 0
}
};
data.sort(orderSort);

结果如下:使用sort对数组中的对象的某个属性进行排序

上一篇:Bootstrap非常简单实用的web前端开发框架


下一篇:(转)Oracle Data Guard配置