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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…