title: what is the correct way to splice an array using for loop, having nested if conditions
body: <p>i am facing this issue of splicing an array.i checked out all the examples i could find but all in vein. the troubles are these nested if conditions inside the for loop .i am doing i-- but not able to go ahead. can anybody help me out and explain the approach.i am adding a snippet. the prob is that, whenever i don't do the i-- operation, and splice the array, alternate removal of elements happens but upon adding the i--, i am not able to proceed any further. i tried --i, but now i am confused as to what i am doing wrong! here m is an array of number from 1 to 20 serially. having length 20. </p>
  
  <pre><code>        var k=13;
          for (var i = 0; i &lt; m.length; i++) {
              if (m[i] &lt; k) {
                  if (i != 0 &amp;&amp; i != m.length) {
                      m.splice(i, 1);
                  }
                  if (i == 0) {
                      m.splice(i, 1);
                  }
                  i--;
              }
          }
  </code></pre>