i want to show array of object's properties in a custom sorted way. following is the array
$scope.weekDays = [
{
"day" : "TUESDAY",
"count": 10
},
{
"day" : "MONDAY",
"count": 20
},
{
"day" : "WEDNESDAY",
"count": 30
},
{
"day" : "SUNDAY",
"count": 60
}];
if we print day from weekDays it is like TUESDAY, MONDAY, WEDNESDAY, SUNDAY
but i want to show in the order "SUNDAY", "MONDAY", "FRIDAY", "TUESDAY","WEDNESDAY"
for this i did the following
$scope.orde = ["SUNDAY", "MONDAY", "FRIDAY", "TUESDAY","WEDNESDAY"];
$scope.Sorted = [];
$scope.SortCustomOrder = function() {
var _c =0;
for(var i = 0; i < $scope.orde.length; i++) {
for (var _i = 0; _i < $scope.weekDays.length; _i++) {
if($scope.weekDays[_i].day==$scope.orde[i]) {
$scope.Sorted[_c] = $scope.weekDays[_i];
_c++;
}
}
}
};
and printed $scope.Sorted. It prints what i said.
Is there any way to simplyfy this or any other mehtods in angularjs?