0

I am getting an array of unix epoch time which I am converting to GMT string. I want to sort the array, how can I go about it?

for(var i in data.results) {
    var date = new Date(data.results[i].lastModifiedAt*1000);
    var day = date.toGMTString();
    $scope.day[i] = day;
}
1
  • $scope.day.sort() should work Commented Jul 19, 2015 at 7:04

1 Answer 1

1

Since you tag the question as angular, you can use ng-repeat with orderBy. Something like:

$scope.results = data.results.map(function(result) {
  result.day = new Date(result.lastModifiedAt*1000).toGMTString()
  return result;
}

And in your html:

<div ng-repeat="result in results | orderBy:'day':true track by $index"></div>

And you will not have to use sort

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.