首页 > 编程语言 > 详细

数组的嵌套排序

时间:2020-06-03 18:41:25      阅读:46      评论:0      收藏:0      [点我收藏+]
// 常规的数组排序的方法  a-b升序  b-a降序
arr.sort(function(a,b) { return a - b })  

// sort内部是有嵌套排序机制的 两级排序

this.productSourceList =   productSourceList.sort(this.sortByTwo)

function sortByTwo(a,b) {
  return a.priority === b.priority ? a.prodsourceId - b.prodsourceId : a.priority - b.priority
}

  备注: 根据优先级从小到大进行排序;优先级相同的情况下,再去根据产品资料的id从小到大进行排序

数组的嵌套排序

原文:https://www.cnblogs.com/glfan/p/13039152.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!