0

I am trying to remove all the rows that don't have the value '2A' or '2B' but whenever I execute the code it deletes every row except the first one.

Here is my bit of code :

function supprimerColonnesInutiles() {
    for(i = 1; i < data.length; i++) {
        if(data[i][13] === '2019-09-30'){
            data.splice(i);
        }    
        if(data[i][2] !== '2A'){
            data.splice(i);
        }
    }
}

This code works perfectly to delete every row with the 2019 date but fails to do what I expect it to do to delete rows that contain 2A as a value (i'd like to keep 2B values as well).

here is the csv file that serves as my array, as you can see the second column contains 2As and 2Bs but also number from 1 to 100.

This is what I get if I execute the code enter image description here

and here is my csv/array enter image description here

My question is what could be causing this issue and how can I fix it ?

Intern
  • 1
  • Why was my question closed ? How do those other posts answer it ? There's clearly an issue here that other posts don't answer. – Intern Feb 07 '21 at 15:38
  • Your problem is splicing in a forward looking `for()` loop which is exactly what the other questions answer. Read the explanations carefully, with emphasis on the indexing problem you have created. You also should be using an OR condition or an else – charlietfl Feb 07 '21 at 15:41

0 Answers0