title: AngularJS - Filtering Greatest Value From JSON
body: <p>I have JSON file with a list of numerical values:</p>
  
  <pre><code>{
      "Entries": {
          "Records" : [
              {
                  "Name": "Mr Happy",
                  "Gender": "Male",
                  "Balance": "100"
              },
              {
                  "Name": "Mr Sad",
                  "Gender": "Male",
                  "Balance": "50"
              },
              {
                  "Name": "Mrs Grump",
                  "Gender": "Female",
                  "Balance": "2000"
              },
              {
                  "Name": "Mr Loud",
                  "Gender": "Male",
                  "Balance": "1000"
              } 
          ]   
  
      }
  }
  </code></pre>
  
  <p>I can display the list of values via a simple <code>ng-repeat</code> :</p>
  
  <pre><code>&lt;li ng-repeat="account in Entries.Records"&gt;
  
      {{ account.Name }},  {{ account.Balance }} 
  
  &lt;/li&gt;
  </code></pre>
  
  <p>But how can i modify/filter this <code>ng-repeat</code> to only show the record with the highest balance?</p>
  
  <hr>
  
  <p>Updated of full controller and service:</p>
  
  <pre><code>app.controller("MyController", function($scope, $http, getReportService) {
  
      $scope.EntriesRecords = [];
  
      getReportService.getReportData(function(data) {
  
          $scope.EntriesRecords = data.Entries.Records;
  
          $scope.maxBalanceAccount = findMaxBalanceAccount();
      });
  
  
      function findMaxBalanceAccount() {
          var result = null;
          for (var i = 0; i &lt; $scope.EntriesRecords.length; i++) {
          var account = $scope.EntriesRecords[i];
              if (result == null || account.Balance &gt; result.Balance) {
                  result = account;
              }
          }
          return result;
      }
  
      console.log($scope.maxBalanceAccount);
  
  });
  
  
  app.factory('getReportService', function($http) {
      return {
          getReportData: function(done) {
              $http.get('/data/records.json')
              .success(function(data) { 
                  done(data);
              })
              .error(function(error) {
                  alert('An error occured');
              });
          }
      }
  });
  </code></pre>