Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript sort array of object by property

function sortByDate( a, b ) {
  if ( a.created_at < b.created_at ){
    return -1;
  }
  if ( a.created_at > b.created_at ){
    return 1;
  }
  return 0;
}

myDates.sort(sortByDate);//myDates is not sorted.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #sort #array #object #property
ADD COMMENT
Topic
Name
3+7 =