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

编程入门 行业动态 更新时间:2024-10-25 02:30:25
本文介绍了如何以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对时间戳数组进行排序

本文发布于:2023-10-24 09:42:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   顺序   时间   desc   lodash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!