title: JavaScript Prime checker not working
body: <p>My prime checker is not working. I think there are simpler ways to do this challenge, but the functionality I need is:</p>
  
  <p>For a given number p:</p>
  
  <p>1) Fill an array numArray with numbers from 2 to p</p>
  
  <p>I have achieved this with: </p>
  
  <pre><code>for (var i=2; i&lt;(p + 1); i++) {
      numArray.push(i);
    };
  </code></pre>
  
  <p>2) While numArray is not empty:</p>
  
  <ul>
  <li><p>add the first number 'prime' in numArray to the array primeArray</p></li>
  <li><p>splice every multiple of prime from numArray</p></li>
  </ul>
  
  <p>My code doesn't use a while loop because I'm not sure how to use one to iterate through the array, but a for loop isn't working either?</p>
  
  <p>CAN PEOPLE JUST RESPOND WITH SUGGESTIONS, NOT COMPLETE FIXES. Definitely please please do not write complete code that finds prime numbers. I'm more interested to know how I can iterate through an array that I keep  slicing depending on elements of the array, and any other pointers about how to structure my code. </p>
  
  <p>Also I'm confused as to why </p>
  
  <pre><code>(numArray[k] % prime == 0)
  </code></pre>
  
  <p>seems to miss numbers?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function checkIfPrime(p) {
    numArray = [];
    primeArray = [];
  
    for (var i = 2; i &lt; (p + 1); i++) {
      numArray.push(i);
    };
  
    for (var j = 0; j &lt; numArray.length; j++) {
      if (primeArray.indexOf(numArray[j]) === -1) { //if numArray of j is not already in primeArray
  
        var prime = numArray[j];
        console.log(prime + " is not in numArray")
  
        primeArray.push(prime);
        console.log(primeArray);
        numArray.splice(j, 1);
        console.log(numArray);
  
  
        for (var k = 0; k &lt; numArray.length; k++) {
          if (numArray[k] % prime == 0) {
            numArray.splice(k, 1);
          };
        }
  
      }
  
    };
  
  }
  
  
  p = 5;
  console.log(checkIfPrime(p));</code></pre>
  </div>
  </div>
  </p>