sort by timestamp javascript code example
Example 1: sort array by date typescript
array.sort((x, y) => +new Date(x.createdAt) - +new Date(y.createdAt));
Example 2: javascript order array by date
const sortedActivities = activities.sort((a, b) => b.date - a.date)
Example 3: sort by ascending javascript
const months = ['March', 'Jan', 'Feb', 'Dec'];
months.sort();
console.log(months);
// expected output: Array ["Dec", "Feb", "Jan", "March"]