title: How to get quanity rate from the given json data in angularjs
body: <p>Json Data :</p>
  
  <pre><code>{
    "food": {
      "rates": {
        "defaultRates": {
          "cardRate": 600,
          "discountedRate": 500
        },
        "otherRates": [
          {
            "cardRate": 600,
            "discountedRate": 400,
            "fields": [
              {
                "name": "Quantity",
                "min": 3,
                "max": 6
              }
            ],
            "name": "3-6 Quantity"
          },
          {
            "cardRate": 600,
            "discountedRate": 300,
            "fields": [
              {
                "name": "Quantity",
                "min": 7
              }
            ],
            "name": "7+ Quantity"
          }
        ]
      },
      "details" : {
        "name" : "Something"
      }
  }
  </code></pre>
  
  <p>JS Code:</p>
  
  <pre><code>$scope.food = angular.copy(JSONObject); // Copied JsonObject
  
  $scope.defaultRates = angular.copy($scope.food.rates.defaultRates);
  $scope.otherRates = angular.copy($scope.food.rates.otherRates);
  
  $scope.quantity = 4;
  
  angular.forEach($scope.otherRates, function (otherRate) {
      angular.forEach(otherRate.fields, function (field) {
          if($scope.quantity &gt;= field.min){
              if(field.max) {
                  if($scope.quantity &lt;= field.max){
                      $scope.discountedRate = angular.copy(otherRate.discountedRate);
                  }
              } else {
                  $scope.discountedRate = angular.copy(otherRate.discountedRate);
              }
          } else {
              $scope.discountedRate = angular.copy($scope.defaultRates.discountedRate);
          }
      })
  });
  </code></pre>
  
  <p>If I console the <code>$scope.discountedRate</code> I'm getting the 7+ quantity rate. I want to get the <code>$scope.discountedRate</code> according to the <code>$scope.quantity</code> I have given.</p>
  
  <p>So, How to get the discounted rate from the json data by comparing the quantity of the food.</p>