EnzyWeiss
EnzyWeiss

Reputation: 198

Filter and remove arrays

I've got a filter method that check if result doesn't contain value from this.state.filter it should be delete.

My problem is method doesn't remove wrong result. It makes null

filter(){
    const {fetchData} = this.state;
  return  fetchData.map((result, index) => (
      (result[3] == this.state.filter) ?
      result :  null //there is my problem
    ))
  }

screens from console.log

before

after

Upvotes: 0

Views: 62

Answers (1)

Dane
Dane

Reputation: 9542

Instead of map you must be using Array.prototype.filter to remove elements from array:

filter() {
  const { fetchData } = this.state;
  return fetchData.filter( (subarray) => (
    subarray[3] === this.state.filter
  ));
}

Upvotes: 4

Related Questions