Remove item from array in React

后端 未结 8 816
醉酒成梦
醉酒成梦 2021-01-03 12:45

I have problem with removeItem function (it should remove current

  • that button is nested in, and item from array on this.state.list), no code currentl
  • 8条回答
    •  抹茶落季
      2021-01-03 13:25

      Removing item from array by index:

      const newList = this.state.list.splice(index, 1);
      

      Removing item from array by value:

      const newList = this.state.list.splice(this.state.list.indexOf(value), 1);
      

    提交回复
    热议问题