Skip to content
Advertisement

Sort by Status then by date JavaScript

I have an array of the following type I wan to sort. I want to sort them by the status and show false ones first and and then sort them by their date. I don’t know if I should use group by then sort.

JavaScript

I have used the below code it sorts the array by status but the date sorting is not working. can someone help me with a better method and what am I doing wrong ? , Thanks

JavaScript

Advertisement

Answer

The reason is that your date is string format,not actually date,you need to change it to date when compare

JavaScript

also,you expression is too complex to read and debug,had better to use () to wrap it or use if else condition instead

JavaScript

working code

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement