如何以desc顺序使用lodash对时间戳数组进行排序 [英] How to sort an array of timestamps using lodash in desc order

查看:1053
本文介绍了如何以desc顺序使用lodash对时间戳数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 lodash 对以下时间戳数组进行排序,因此最新的时间戳在前[3].

I want to sort the following array of timestamps using lodash so the latest time stamp is first [3].

代码:

let timestamps = ["2017-01-15T19:18:13.000Z", "2016-11-24T17:33:56.000Z", "2017-04-24T00:41:18.000Z", "2017-03-06T01:45:29.000Z", "2017-03-05T03:30:40.000Z"]

const sorted = _.sortBy(timestamps);

这不符合我的预期,我相信它是按升序对它们进行排序的.

This does not work as i expect, i believe its sorting them but in asc order.

推荐答案

如何使用lodash对时间戳数组进行排序

How to sort an array of timestamps using lodash

此代码已经使用lodash正确地对时间戳进行了排序:

This code is already sorting timestamps correctly using lodash:

const sorted = _.sortBy(timestamps);

按升序排列,只需使用以下方法反转结果:

just in ascending order, simply reverse the result using:

const sorted = _.sortBy(timestamps).reverse();

这篇关于如何以desc顺序使用lodash对时间戳数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆