标签:style io ar cti line on sp har
function createComparisonFunction(propertyName){
return function(object1,object2){
var value1=object1[propertyName];
var value2=object2[propertyName];
if(value1<value2){
return -1
}else if(value1>value2){
return 1
}else {
return 0;
}
}}
例如:var data=[{name:"zachary",age:28},{name:"nicholas",age:29}];
data.sort(createComparisonFunction("name"));
alert(data[0].name);//Nicholas 此时是根据name排序
3、假设有一个对象数组,想根据某个对象属性对数组进行排序时,布布扣,bubuko.com
标签:style io ar cti line on sp har
原文地址:http://www.cnblogs.com/danmohendt/p/3920150.html