【发布时间】:2019-05-29 05:30:14
【问题描述】:
我想从数组中删除特定元素,我从输入中获取元素的键。 我希望能够仅通过知道密钥来删除元素。
这是数组:
state ={
splitAmount : [{
"SplitAmount0": this.props.data.amount1
}, {
"SplitAmount1": this.props.data.amount2
}, {
"SplitAmount2": this.props.data.amount3
}]
}
删除功能:
removeSplitAmount(e) {
console.log("remove",e.target.name)
let array = [...this.state.splitAmount];
let index = this.state.splitAmount.IndexOf(p => p == e.target.name )
if (index !== -1) {
array.splice(index, 1);
this.setState({splitAmount: array});
}
}
【问题讨论】:
标签: javascript reactjs react-redux