title: Sum pervious values of total with each iteration - Angular JS
body: <p>I have a controller of Angular JS which sum numbers of values with the help of range loop but now I have requirement need to sum previous value of total with each iteration. I have tried with so many filters but no success.  I have require desired result. Helps are definitely appreciated.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = [
    {
      "unique_id": "CS",
      "college": "BSCS",
      "arr_length": 1,
      "program_section": [
        {
          "question": "Q1",
          "total": 135,
          
        },
        {
          "question": "Q2",
          "total": 142,
          
        },
        {
          "question": "Q3",
          "total": 135,
          
        },
        {
          "question": "Q4",
          "total": 137,
          
        },
        
      ]
    },
    {
      "unique_id": "MBA",
      "college": "BBA",
      "arr_length": 2,
      "program_section": [
        {
          "question": "Q1",
          "total": 175,
          
        },
        {
          "question": "Q2",
          "total": 142,
          
        },
        {
          "question": "Q3",
          "total": 165,
          
        },
        {
          "question": "Q4",
          "total": 137,
          
        },
        
      ]
    },
    {
      "unique_id": "CA",
      "college": "Account",
      "arr_length": 1,
      "program_section": [
        {
          "question": "Q1",
          "total": 145,
          
        },
        {
          "question": "Q2",
          "total": 162,
          
        },
        {
          "question": "Q3",
          "total": 125,
          
        },
        {
          "question": "Q4",
          "total": 117,
          
        },
        
      ]
    }
  ];
  var app = angular.module('myApp', []);
  app.controller('customersCtrl', function($scope, $http) {
      $scope.names = arr;
  }).filter('range', function() {
    return function(input, total) {
      total = parseInt(total);
  
      for (var i=0; i&lt;total; i++) {
        input.push(i);
      }
  
      return input;
    };
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
  &lt;div ng-app="myApp" ng-controller="customersCtrl"&gt; 
  
  &lt;table  border="1"&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;td&gt;Question&lt;/td&gt;
      &lt;td ng-repeat="x in names"&gt;{{ x.college }}&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
        &lt;tr ng-repeat="n in [] | range:4"&gt;
          &lt;td&gt;
              {{ names[0].program_section[n].question }}
          &lt;/td&gt;
          &lt;td width="100px" ng-repeat="x in names"&gt;
             {{ x.program_section[n].total }}
          &lt;/td&gt;
        &lt;/tr&gt;
  &lt;/tbody&gt;
    
  &lt;/table&gt;
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <blockquote>
    <p>Desired Result</p>
  </blockquote>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table width="426" border="1"&gt;
    &lt;tr&gt;
      &lt;td width="79"&gt;Question&lt;/td&gt;
      &lt;td &gt;BSCS&lt;/td&gt;
      &lt;td &gt;BBA&lt;/td&gt;
      &lt;td &gt;Account&lt;/td&gt;
      &lt;td &gt;Total&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Q1&lt;/td&gt;
      &lt;td&gt;135&lt;/td&gt;
      &lt;td&gt;175&lt;/td&gt;
      &lt;td&gt;145&lt;/td&gt;
      &lt;td width="50" &gt;455&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Q2&lt;/td&gt;
      &lt;td&gt;142&lt;/td&gt;
      &lt;td&gt;142&lt;/td&gt;
      &lt;td&gt;162&lt;/td&gt;
      &lt;td width="50" &gt;446&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Q3&lt;/td&gt;
      &lt;td&gt;135&lt;/td&gt;
      &lt;td&gt;165&lt;/td&gt;
      &lt;td&gt;125&lt;/td&gt;
      &lt;td width="50" &gt;425&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Q4&lt;/td&gt;
      &lt;td&gt;137&lt;/td&gt;
      &lt;td&gt;137&lt;/td&gt;
      &lt;td&gt;117&lt;/td&gt;
      &lt;td width="50" &gt;391&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>