title: JavaScript go through array and subtract each item with next
body: <p>I have an array which looks like this:</p>
  
  <pre><code>0: 0
  1: 1
  2: 2
  3: 3
  4: 4
  5: 5
  6: 6
  7: 7
  8: 8
  9: 9
  10: 10
  11: 11
  12: 12
  13: 13
  14: 14
  15: 15
  16: 16
  17: 17
  18: 21
  19: 22
  20: 23
  </code></pre>
  
  <p>I want to subtract each value with the next and save that subtracted value how do I do that</p>
  
  <p>So far I have done this</p>
  
  <pre><code>    _this.elements.forEach(function (element, index) {
          console.log(parseInt(element) - parseInt(element[index])); 
  
      });
  </code></pre>
  
  <p>But it keeps returning undefined</p>