0

Could please anyone explain me why I´m getting this error when I´m trying to remove the last item of an array.

Here the array.

this.customsTypes = [
    {
        "id": "D1",
        "title": "d1",
        "icon": "",
        "hasDeleteIcon": true,
        "deleteIcon": "<img src=\"assets/icons/trash_icon.svg\">"
    },
    {
        "id": "D2",
        "title": "d2",
        "icon": "",
        "hasDeleteIcon": true,
        "deleteIcon": "<img src=\"assets/icons/trash_icon.svg\">"
    },
    {
        "id": "DISTRIBUCIÓN__18/07/2023",
        "title": "Distribución  18/07/2023",
        "icon": "",
        "hasDeleteIcon": true,
        "deleteIcon": "<img src=\"assets/icons/trash_icon.svg\">"
    }
]

Here the use of splice:

const idIndex = this.customsTypes!.findIndex((e) => e.id === id);
this.customsTypes!.splice(idIndex, 1);

Here the error I get on console:

Uncaught TypeError: Cannot delete property '2' of [object Array] at Array.splice ()

3
  • 1
    Does this answer your question? Cannot delete property '1' of [object Array] Commented Jul 18, 2023 at 10:51
  • Can you post how are you using this code. What is your id variable here Commented Jul 18, 2023 at 11:05
  • id value is the value of the property id. For example "D2" Commented Jul 18, 2023 at 15:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.