Time Sorting Ascending or Descending Order in Javascript

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.

details.sort(SortByTime);

 

 

You might also like:

Use java script file client side and server side at a time in node js

30-07-2017 node js include call javascript

How to get id by using name attribute in javascript

20-03-2017 html id name javascript

Convert Time 24 hrs to 12 hrs format In javascript

12-03-2017 date javascript 12hrs convert

Filter for replace text in Angular Js

05-03-2017 filter replace angular js

How to set or update or push the values into Object in javacript

27-02-2017 javascript set update push object