Reputation: 95
I've an array of objects which needs to be sorted by email ids, where an email id is an object key. I also have a function to sort. For example:
var bills=[name: "somename",email:"[email protected]", name:"somename2",email:"[email protected]"]
/* sort function */
function sortArray(bills,email) {
bills.sort(function (a,b) {
return a[email] > b[email];
});
}
The array is sorted by email id in the ascending order when tested in a desktop browser but its not sorted in a mobile browser (IOS:safari & chrome). It appears as it was entered in the array. Interestingly, in the broswer, the array is sorted by email id in the ascending order even before the sort function is applied. I tried the stackoverflow archives and this is the closest that I could get to: My Angular JS app works in desktop browser, but not in a mobile browser but it does not seem to address this issue in particular as the other areas of the application is working as expected. I would be grateful if anyone could help me out here. Thanks for your time.
Regards, Aj
Upvotes: 0
Views: 130
Reputation: 95
I managed to resolve this using angular filter
$scope.array = $filter('orderBy')($scope.array,'payee');
payee is one of the object attributes of an object in the array $scope.array.
Upvotes: 1