title: array splice not working as expected inside the function
body: <p>Expected output : <code>['jan']</code><br>
  Actual output: <code>['jan', 'apple']</code></p>
  
  <p><code>forEach</code> function gets stopped after the splice operation. 
  the commented code is working as expected but when I try to use similar with foreach, the code is not working as expected.</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>var mainArr = ['jan', 'feb', 'apple'];
  var exArr = ['feb', 'apple'];
  removeGivenArr(mainArr, exArr);
  
  function removeGivenArr(mainArr, exArr) {
    mainArr.forEach((item, index) =&gt; {
  
      if (exArr.includes(item)) {
        console.log(item);
        mainArr.splice(index, 1);
      }
      console.log(mainArr);
  
    });
  }
  
  // function removeGivenArr(mainArr, exArr){
  
  //     const output = [];
  //     for(let element of mainArr){
  //         if(!exArr.includes(element)){
  //             output.push(element);
  //         }
  
  //     return output;
  //     }   
  // }</code></pre>
  </div>
  </div>
  </p>