title: Finding totals of certain strings in an Array
body: <p>I have two arrays, one with tax codes (emptaxdeductcode), and one with the amounts paid for those tax codes (emptaxamt).</p>
  
  <p>I am trying to find the amounts paid for <em>only the tax codes ending in 31</em>. These tax codes have different number of characters, but the ones I need are always 12 characters.</p>
  
  <p>Trying to use a simple for loop but it appears to be breaking at line 3. It's always showing 0 even for those that have the tax code(s) in question:</p>
  
  <pre><code>var returnedValue = 0;
  for (var q = 0; q &lt; emptaxdeductcode.length; q++) {
      if (emptaxdeductcode[q].substring(10,11) == "31") {
          returnedValue += emptaxamt[q];
      } else {
          0;
      }
  }
  returnedValue;
  </code></pre>
  
  <p>I've tried the following just as a test and it is returning true:
  (This tax code isn't always in [5] so I can't just use that. Plus there are people who have multiple tax codes ending in 31)</p>
  
  <pre><code>if (emptaxdeductcode[5].substring(10,11) == "31") {
      "TRUE";
  } else {
      "FALSE";
  }
  </code></pre>
  
  <p>So it must be the substring within the for loop that is causing problems. Any guidance would be greatly appreciated!</p>
  
  <p>Edit: Here is a sample of the data. Apologies if this exports strangely - not exactly sure how to make tables:</p>
  
  <p>emptaxdeductcode    |   emptaxamt</p>
  
  <p>--- |   ---</p>
  
  <p>00-10   |   55.36</p>
  
  <p>00-11   |   8.33</p>
  
  <p>00-12   |   35.63</p>
  
  <p>39-20   |   17.64</p>
  
  <p>39-22   |   0.40</p>
  
  <p>390770040-31    |   9.48</p>
  
  <p>390770040-32    |   2.00</p>
  
  <p>Edit2: This software I am using to build this report does not support many JS utilities/libraries. A lot of posts on stackoverflow with similar issues to me have been resolved with 'prototype' functions or AngularJS and things like that. Unfortunately that won't work for me.</p>