I am trying to update the value of my object elements whenever one of the object is deleted. However, I always get the Uncaught ReferenceError: i is not defined error on my console.
Here is my code deleteTask(event) {this.todoTasks = this.todoTasks.filter(task => task.id !== event.target.name);this.updateId();console.log(this.todoTasks);}updateId(){for(i=1; i<=this.todoTasks.length; i++){this.todoTasks[i-1].id = i;}}1 Antwort
Hi Roman,You have missed declaring the variable by using either var or let for variable i . Here is your updated code:
ThanksGulshan RajdeleteTask(event) {
this.todoTasks = this.todoTasks.filter(task => task.id !== event.target.name);
this.updateId();
console.log(this.todoTasks);
}
updateId(){
for(var i=1; i<=this.todoTasks.length; i++){
this.todoTasks[i-1].id = i;
}
}