1

I am using delete in order to try to delete an item on an array;

const handleRowDeletion = index => {
    const inputsAdded = shareStructureInputs;
    const inputs = startupFourthStepForm.shares_estructure;

    delete inputs[index];
    delete inputsAdded[index];
}

I can see the first array inputsAdded getting deleted at the proper index but not the second one inputs.

This is what inputsAdded returns:

[
  "share-structure-input-0",
  "share-structure-input-1",
  "share-structure-input-2"
]

And inputs:

[
  {
    "name": "Name 1",
    "percentage": 10
  },
  {
    "name": "Name 2",
    "percentage": 10
  },
  {
    "name": "Name 3",
    "percentage": 80
  }
]

And I call the function on a map

                <Button onClick={() => handleRowDeletion(index)}>
                  - Delete Row
                </Button>
Non
  • 7,689
  • 14
  • 55
  • 110
  • isn't `delete` only used for objects? you're not using `delete` on any object properties – jtylerm Jun 18 '19 at 15:23
  • Theres's a better duplicate which exactly answers your question, https://stackoverflow.com/questions/500606/deleting-array-elements-in-javascript-delete-vs-splice – Avin Kavish Jun 18 '19 at 15:24

0 Answers0