title: Remove several array elements by index and store removed elements
body: <p>How can I remove multiple items by index and save the removed items. I get the currently selected values from a ListBox (e.g.<code>selectedValues = [1, 4, 2]</code>) and have two arrays <code>actives</code> <code>availables</code>. I try to move the selected elements in an efficient way.</p>
  
  <p>That's how I would solve this:</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 actives = [ "a", "d", "k", "e"]
  var availables = [ "m", "o", "v" ]
  var selectedValues = [3, 1]
  var elementsToMove = []
  
  selectedValues.forEach(i =&gt; {
    elementsToMove.push(actives[i])
  })
  
  actives = actives.filter(item =&gt; !elementsToMove.includes(item))
  availables = availables.concat(elementsToMove);
  
  console.log(actives);
  console.log(availables);</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Expected output:</strong></p>
  
  <pre><code>actives = [ "a", "k" ]
  availables = [ "m", "o", "v", "e", "d"] 
  </code></pre>
  
  <p><strong>Note:</strong> The length of the arrays can be very large.</p>