我希望能使用 Lodash 对以下时间戳数组进行排序,使最新的时间戳排在第一位 [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);
这不符合我的预期,我认为它正在排序,但是按升序排序。
_.orderBy()
而不是_.sortBy()
。 - Alexanderarr.sort( (a, b) => b > a ? 1 : -1 )
。 - gurvinder372