【发布时间】:2021-09-05 01:48:51
【问题描述】:
我有这个函数需要删除从数组中单击的项目。我确定它是一个简单的修复,但它不会从数组中删除它。我认为这与我如何在按钮中执行功能有关?我不完全确定。 错误:TypeError:e.findIndex 不是函数
const deleteClaim = (claim,value) => {
const index = claim.findIndex(element => element === value); // 1
const result = claim.splice(index, 1);
return result
}
按钮是
<button onClick={(e) => deleteClaim(claim, e.target.value)} >X </button>
【问题讨论】:
-
按钮在你的代码中是否有值属性?
-
TypeError: e.findIndex 不是函数
-
'Result' 可能是正确的答案。但是,您是否将其分配回列表中?
-
你是什么意思结果是最好的答案?
-
如果这是react,则需要用更新后的数组设置状态。
标签: javascript reactjs