Fastest way to sort an array by timestamp
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.