javascript - 通过一个函数中的多个比较对对象数组进行排序
问题描述
我有一个对象数组:
const arr = [
{
name: 'Kevin',
timestamp: "1617834779855"
},
{
name: 'Louis',
timestamp: "1617334735485"
},
{
name: 'Adisson',
timestamp: "1616530999700"
},
]
我需要按最近的时间戳和名称按字母顺序排序。现在我有一个按日期排序的排序函数,但我不知道如何将名称添加到排序函数中
const i = arr.sort((a, b) => b.timestamp - a.timestamp);
我的第一个想法是添加另一个排序函数,但我不希望它再次遍历数组,因为在我的应用程序中,数组的长度超过 1000 个
解决方案
推荐阅读
- c# - System.Drawing.Common DrawString 无法在 Linux 中正确呈现文本
- python - 在我的亚马逊卖家页面中使用 Beautiful Soup 解析未发货的订单;找不到html标签
- linux - 如何知道哪个内核发送了处理器间中断?
- python - 按几列排序唯一,然后合并不匹配列中的值
- javascript - 如何让我的文字跟随我在 Phaser 3 中的玩家?
- reactjs - 函数已绑定,但仍然出现 Uncaught TypeError: Cannot read property 'name' of undefined
- php - 为什么下拉列表中的选项值不显示?
- react-native - 如何在钩子中渲染之前调用函数反应原生?
- listview - 如何在颤动中删除PageView页面之间的空间
- python - 将 DataFrame A 中的索引与 DataFrame B 的列号匹配