sort date array javascript
const sortedActivities = activities.sort((a, b) => b.date - a.date)
array.sort(function(a,b){
// Turn your strings into dates, and then subtract them
// to get a value that is either negative, positive, or zero.
return new Date(b.date) - new Date(a.date);
});
const activities = [
{ title: 'Hiking', date: new Date('2019-06-28') },
{ title: 'Shopping', date: new Date('2019-06-10') },
{ title: 'Trekking', date: new Date('2019-06-22') }
]
Also in JavaScript:
- in react js how to access history in component
- How to access the request body when POSTing using Node.js and Express
- javascript submit a form
- missing json after pyinstaller
- javascript regex match character from a set of characters
- convert a string to number in javascript
- java script functions
- tesseract.js
- node save json to file
- add style javascript
- how to get width in javascript
- how to run electron and react using concurrently
- hooks in react
- looping through an object of objects with arrays
- electron didn't know require
- node downgrade windows
- how to get element of an array in javascript
- javascript add input
- casl react redux
- javascript check if array is in array
- js join two arrays
- javascript create array with null values
- testing a function in jest on click react
- hoe verbind je de nodemcu 8266 met adafruit io