1

i have image array in Flatlist like this:

a = ['image1','image2','image3']

i have index of array and i want to remove image2, it removed image1 and image3

when i remove image1 and it removed image2 and image3

remove image3 => remove image1 and image2

code I wrote

delete = index => {
    console.log(index);
    this.setState({ image: this.state.image.splice(index, 1) })
}

Why is it like that?

  • `.splice()` returns *an array of all deleted elements*. The exact opposite of an array of all elements except the ones that were deleted. Besides, you shouldn't be mutating your state. – VLAZ Mar 21 '21 at 15:30

0 Answers0