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 ()
idvariable here