10 examples of 'javascript sort date ascending and descending' in JavaScript

Every line of 'javascript sort date ascending and descending' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
53function sortDates(allDates){
54 if (selection == "new" || selection == "updated") {
55 allDates.sort(function(a,b){return new Date(b.date) - new Date(a.date)}); // sorts the dates into ascending order
56 }
57 if (selection == "old") {
58 allDates.sort(function(a,b){return new Date(a.date) - new Date(b.date)}); // sorts the dates into descending order
59 }
60 return allDates;
61}
15export function date_sort_asc (date1: Date, date2: Date) {
16 // This is a comparison function that will result in dates being sorted in
17 // ASCENDING order. As you can see, JavaScript's native comparison operators
18 // can be used to compare dates. This was news to me.
19 if (date1 > date2) return 1;
20 if (date1 < date2) return -1;
21 return 0;
22}
11export default function sortDates(
12 arrayOfDates: Array
13): Array {
14 return arrayOfDates.sort(compareMomentDates);
15}
86function sortDate(a, b) {
87 return b.timestamp - a.timestamp;
88}
361articles.sort(function dateSorter(a, b) {
362 return (Date.parse(b.date)) - (Date.parse(a.date));
363});
9function sortDates() {
10 return _.sortBy(arguments, function (d) {
11 return d.getTime();
12 });
13}
167export function sortByDate (a, b) {
168 return a.date - b.date
169}
169function comparator(a, b)
170{
171 var item1 = a.layer[sortColumnIdentifier] || 0;
172 var item2 = b.layer[sortColumnIdentifier] || 0;
173 return item1 - item2;
174}
34function sortByDate(a, b) {
35 if (a.publishedOn < b.publishedOn) {
36 return 1;
37 } else if (a.publishedOn > b.publishedOn) {
38 return -1;
39 }
40 return 0;
41}
93static sortFunctionAlphabeticDescending(a, b) {
94 return Sortable.sortFunctionAscending(b, a);
95}

Related snippets