function  compare(property,sort){

return function(a,b){

var value1=a[property];

var value2=b[property];

if(sort==1){

return value1 - value2;

}else{

return value2 - value1;

}

}

};

调用 arr.sort(compare(property,1))

sort =1 是正序

sort = -1 是倒序

 

相关文章:

  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-05-29
  • 2022-12-23
  • 2018-09-21
  • 2022-12-23
相关资源
相似解决方案