JS提取数字进行排序JS提取数字进行排序

//records数组里是一些对象。对象的structureCode是功能位置码。

replace(/[^0-9]/ig,"") 正则表达式是强制提取出数字

JS提取数字进行排序

function sortFFC(a,b){
    return parseInt( b.data.structureCode.substring(5+1).replace(/[^0-9]/ig,""),10)-parseInt( a.data.structureCode.substring(5+1).replace(/[^0-9]/ig,""),10);
}
//开始排序
records = records.sort(sortFFC);

降序和升序就a-b和b-a的区别。

JS提取数字进行排序

 

相关文章:

  • 2021-07-10
  • 2021-11-20
  • 2022-12-23
  • 2022-02-13
  • 2021-10-31
  • 2022-12-23
  • 2021-12-28
  • 2021-12-25
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-06-03
  • 2021-12-19
  • 2021-05-23
相关资源
相似解决方案