有,sort()。
使用如下:
原代码及效果:
var fileArr = [];
var file = {};
file.name = 'a';
file.date = '2021-04-23';
fileArr.push(file);
var file = {};
file.name = 'b';
file.date = '2021-04-22';
fileArr.push(file);
var file = {};
file.name = 'c';
file.date = '2021-04-25';
fileArr.push(file);
console.log(fileArr);
排序的代码及效果:
var fileArr = [];
var file = {};
file.name = 'a';
file.date = '2021-04-23';
fileArr.push(file);
var file = {};
file.name = 'b';
file.date = '2021-04-22';
fileArr.push(file);
var file = {};
file.name = 'c';
file.date = '2021-04-25';
fileArr.push(file);
//升序排列
fileArr.sort(function (a, b) {
if (a.date < b.date){
return -1;
}else if (a.date > b.date){
return 1;
}
});
console.log(fileArr);
参考博客:
https://www.cnblogs.com/taxpolat/p/12744534.html
推荐阅读:
https://www.w3school.com.cn/tiy/t.asp?f=js_array_sort_object_2
https://www.w3school.com.cn/js/js_array_sort.asp