I have an array of objects, an example of an object is:
$scope.object = {
Title: 'object1',
Description: 'lorem ipsum',
Value: 123
};
So my array would consist of several object with these attributes, how can I find the object with the highest 'value', in my array?
I have looked into other questions, like this, but they are about arrays with pure values in them, not objects.
What I'd really want is to find the object with the highest value inside my html, maybe using angular $filter, something like this:
ng-repeat="item in objectArray | filter: filterHere "
But it would also work with a function, right now I do it like this, but I don't like this solution at all:
var value = 0;
angular.forEach($scope.objectArray, function(object){
if(object.Value > value){
value = object.Value;
$scope.itemToSeeInView = object;
}
});
So if the value of the object is greater than the var value
item to see in view is set to that object, if the $filter in the view won't work, could this function be improved?