How to sort an array of timestamps using lodash in desc order

前端 未结 7 1166
情话喂你
情话喂你 2021-01-12 22:46

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

Code:

let timestamps = [\"2017-         


        
7条回答
  •  醉梦人生
    2021-01-12 23:23

    How to sort an array of timestamps using 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();
    

提交回复
热议问题