javascrpit sort()数组对象中排序
Posted 进军码农
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascrpit sort()数组对象中排序相关的知识,希望对你有一定的参考价值。
/*ionic 调用 * @param attr 排序的属性 如number属性 * @param rev true表示升序排列,false降序排序 * */ commonSortMethod(attr,rev){ //第二个参数没有传递 默认升序排列 if(rev == undefined){ rev = 1; }else{ rev = (rev) ? 1 : -1; } return function(a,b){ a = a[attr]; b = b[attr]; if(a < b){ return rev * -1; } if(a > b){ return rev * 1; } return 0; } }
arrt.sort(this.commonSortMethod(atrr,false))
以上是关于javascrpit sort()数组对象中排序的主要内容,如果未能解决你的问题,请参考以下文章