且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从组件状态中的数组中删除元素

更新时间:2023-12-05 18:20:10

我见过的最干净的方法是使用过滤器

The cleanest way to do this that I've seen is with filter:

removeItem(index) {
  this.setState({
    data: this.state.data.filter((_, i) => i !== index)
  });
}