Time Sorting Ascending or Descending Order in Javascript

ascending order
descending order

I have an object like 

var details = [{id:1,fromtime:10:00},{id:2,fromtime:20:00},{id:3,fromtime:15:00}];

I want show the records by from time order.  Here is the javascript code for time sorting.

function SortByTime(a,b){
    var fromtime1 = a.fromtime;
    fromtime1 = parseInt(fromtime1.trim().replace(':','')); // 900				
    var	fromtime2 = b.fromtime;
    fromtime2 = parseInt(fromtime2.trim().replace(':','')); // 1100
    if(fromtime1 > fromtime2){
        return ((fromtime1 < fromtime2) ? -1 : ((fromtime1 > fromtime2) ? 1 : 0));					

Here is the code for calling above function.




You might also like:

Check null values in JavaScript?

04-02-2019 JavaScript null check null value

File Upload Using Angular Js and Node Js

28-05-2018 AngularJs Node js file upload multer module

Get previous date from given date in javascript

06-03-2017 date javascript previous date

Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js

05-03-2017 mm-dd-yyyy HH:MM date formats angular js

Get Unique values from array/object in javascript

19-02-2017 javascript unique remove repeated values from array