-1

i want to sort my json response by date ,here is the javascript function

function successCallback(responseObj){

    $.each(responseObj.allRecom.recom,function(index){

    var data=JSON.stringify(responseObj); //contains json response
    alert(responseObj.allRecom.recom[index].recomDate);//it contains date value from response.
    var date=new Date(responseObj.allRecom.recom[index].recomDate);
         date=date.toLocaleString(); //converted to local date string
    });
}

now what i want is whatever the response will be come ,it should be sorted by date.thanks

user3855674
  • 25
  • 1
  • 7
  • You can find some useful answers to this topic here: **[Sort Javascript Object Array By Date](http://stackoverflow.com/a/26759127/2247494)** – jherax Nov 05 '14 at 14:09

1 Answers1

0

Put every object in an array and then call these function:

dates.sort(function(a,b){return a-b}); //asc
dates.sort(function(a,b){return b-a}); //desc

just change 'dates' to corresponding name of the array

lowselfesteemsucks
  • 747
  • 1
  • 10
  • 21