user2851669
user2851669

Reputation:

AngularJS – how to sort array of unix epoch time

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;
}

Upvotes: 0

Views: 552

Answers (1)

Avraam Mavridis
Avraam Mavridis

Reputation: 8920

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

Upvotes: 1

Related Questions