0

I have an array, and I want to delete elements that have status equal to true (as seen in this part of code)

listArray.forEach((element, index) => {
        if (element.status === true) {
            listArray.splice(index, 1);
        }
    });

The problem is that, if, for example, the first, second and third elements have status true, than the second element will not be deleted

Eugen-Andrei Coliban
  • 1,060
  • 2
  • 12
  • 40

2 Answers2

1

Try this:

listArray.filter(element => element.status === false)

You can also do:

listArray.filter(element => !element.status)
turhanco
  • 941
  • 10
  • 19
-2

try this:

listArray = listArray.filter(element => !element.status);
assembler
  • 3,098
  • 12
  • 43
  • 84