var newArray = [{
  name: "aaa",
  value: 0
},
{
  name: "ddd",
  value: 3
},
{
  name: "bbb",
  value: 1
},
{
  name: "eee",
  value: 4
},
{
  name: "ccc",
  value: 2
}];
function compare(property) {
  return function (a, b) {
    var value1 = a[property];
    var value2 = b[property];
    return value1 - value2;
  }
}
console.log(newArray.sort(compare("value")))

 

相关文章:

  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2021-11-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
相关资源
相似解决方案