title: How to delete rows from table that are unequal to a certain value?
body: <p>I have a table that looks like this</p>
  
  <pre><code>R1C1     R1C2     R1C3
  R2C1     R2C2     R2C3
  R3C1     R3C2     R3C3
  </code></pre>
  
  <p>and a function that removes a row from the table when a particular cell value is found. That works fine, see function code below where the result is that row 1 and 3 get deleted</p>
  
  <p>However, when I want to do the opposite - keep only the rows that contain the specified cell values by changing the comparison operator from 0 to -1 (what indexOf() returns if it doesn't find the string), the function deletes all rows and not row 2 as I expected. </p>
  
  <p>Can anyone shed some light on this and provide me with a solution on how to accomplish what I want?</p>
  
  <p>Here is the function code:</p>
  
  <pre><code>function doFunction() {
  
  let array = ['R3C2','R1C3'];
  
  for (var i = 0; i &lt; array.length; i++) {
  
      var removeRowWithCell = array[i];
  
      // change the comparison below to === -1 and it deletes all rows
  
      $('td').filter(function() {
          return $(this).text().indexOf(removeRowWithCell) === 0;
      }).closest('tr').remove();
  
     }
  }
  </code></pre>