Sort array of objects by single key with date value

后端 未结 19 1345
情话喂你
情话喂你 2020-11-22 10:56

I have an array of objects with several key value pairs, and I need to sort them based on \'updated_at\':

[
    {
        \"updated_at\" : \"2012-01-01T06:25         


        
19条回答
  •  清酒与你
    2020-11-22 11:54

    With ES2015 support it can be done by:

    foo.sort((a, b) => a.updated_at < b.updated_at ? -1 : 1)
    

提交回复
热议问题