Fastest way to sort an array by timestamp

前端 未结 1 1939
眼角桃花
眼角桃花 2020-12-05 13:52

how can i sort this array by timestamp and what is the fastest way (array has many many entries)?

my array

  myList = new Arra         


        
相关标签:
1条回答
  • 2020-12-05 14:34
    myList.sort(function(x, y){
        return x.timestamp - y.timestamp;
    })
    

    myList is a JavaScript array, which supports the sort method. This method accepts a function as argument, which sorts the array according to the returned value.

    Currently, the sort algorithm will place the element with the lowest timestamp first. Swap x.timestamp and y.timestamp if you want to sort the array in the other direction.

    0 讨论(0)
提交回复
热议问题