Q:

Get element with max value from an object in Angular

Couldn't find anything about this.
I have this controller:
app.controller('StatsCtrl', function ($scope, $http) {
 $http.get('stats.json').success(function(data) {
    $scope.stats = data;
 });
});

The stats.json has:
{"lang":{"en":28,"und":1,"ja":9,"es":14,"ru":1,"in":1,"ko":1,"th":1,"ar":1}}

What I need is to assign the maximum value from the lang object to $scope.max in the controller. What is the best way to do this?

A:

You can do it with a couple of native methods:
$scope.max = Math.max.apply(null, Object.keys(data.lang).map(function(key) {
    return data.lang[key];
}));

