vue+js排序方法JavaScript localeCompare() 方法

res.devices_list={
device_last_use_date:'111110000' //13位时间戳或者时间格式的时间
}
res.devices_list.sort((a, b) => b.device_last_use_date.localeCompare(a.device_last_use_date)); //升序或降序

注释说明:比较结果的数字。
如果 b.device_last_use_date 小于 a.device_last_use_date,则 localeCompare() 返回小于 0 的数。如果 b.device_last_use_date 大于 a.device_last_use_date,则该方法返回大于 0 的数。如果两个字符串相等,或根据本地排序规则没有区别,该方法返回 0。
实例
在本例中,我们将用本地特定排序规则对字符串数组进行排序:

var str;
str.sort (function(a,b){return a.localeCompare(b)})
原文地址:https://www.cnblogs.com/guanhuohuo/p/12533702.html