无法使用Delete删除数组索引/项目

时间:2019-06-18 15:18:50

标签: javascript ecmascript-6

我正在使用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>

0 个答案:

没有答案