javascript - 无法使用 delete 删除数组索引/项目
问题描述
我正在使用delete
以尝试删除数组上的项目;
const handleRowDeletion = index => {
const inputsAdded = shareStructureInputs;
const inputs = startupFourthStepForm.shares_estructure;
delete inputs[index];
delete inputsAdded[index];
}
我可以看到第一个数组inputsAdded
在正确的索引处被删除,但不是第二个inputs
。
这是inputsAdded
返回:
[
"share-structure-input-0",
"share-structure-input-1",
"share-structure-input-2"
]
并且inputs
:
[
{
"name": "Name 1",
"percentage": 10
},
{
"name": "Name 2",
"percentage": 10
},
{
"name": "Name 3",
"percentage": 80
}
]
我把这个函数称为map
<Button onClick={() => handleRowDeletion(index)}>
- Delete Row
</Button>
解决方案
推荐阅读
- html - 打印时背景图像显示不正确(另存为 PDF)但可以使用
- python - 为什么我无法在 python 中使用 selenium 抓取同一网站的多个 URL?
- node.js - 在节点后面触发getSignedUrl函数,传递到前面
- spring - 如何为特定 url 启用 spring 安全会话管理
- javascript - 从字符串中删除字符然后反转它
- arrays - Google Cloud - BigQuery - 在结构中转置 2 个字符串列
- azure - Arduino Yun 没有得到 Azure API 的响应
- python - React JS 将值添加到另一个文件中的 const 值
- web - Hugo 中的两级菜单
- java - 在 VS Code 中创建 Apache Netbeans 宏