title: Javascript: take every nth Element of Array
body: <p>I get an Array with an unknown Number of data.
  But I only have an predefined amount of data to be shown/store.
  How can I take every nth Element of the initial Array and reduce it in JavaScript?</p>
  
  <p>Eg.: I get an Array with size=10000, but are only able to show n=2k Elements.</p>
  
  <p>I tried it like that:
  delta= Math.round(10*n/size)/10 = 0.2 -> take every 5th Element of the initial Array.</p>
  
  <pre><code>for (i = 0; i &lt; oldArr.length; i++) {
    arr[i] = oldArr[i].filter(function (value, index, ar) {
      if (index % delta != 0) return false;
      return true;
    });
  }
  </code></pre>
  
  <p>With 0.2 it´s always 0, but with some other deltas (0.3) it is working.  Same for delta=0.4, i works, but every second Element is taken with that. What can I do to get this to work?</p>