- 单纯的数组数字进行排序,见vue使用sort()方法排序
- 根据数组中对象为数字情况进行排序,见下面代码
sortBykey(ary, key) {
return ary.sort(function (a, b) {
let x = a[key]
let y = b[key]
return ((x < y) ? -1 : (x > y) ? 1 : 0)
})
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 根据数组中对象为字母情况进行排序,见下面代码
sortList(lists){ // lists传的是数组
return lists.sort((a, b) => {
return a['grapheme'].localeCompare(b['grapheme']) // grapheme为字母对应的属性名
})
}
- 1
- 2
- 3
- 4
- 5
Comments | NOTHING