You need to sign in to do that
Don't have an account?
Roman Regmi
For loop not working inside LWC javascript.
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;
}
}
You have missed declaring the variable by using either var or let for variable i. Here is your updated code:
Thanks
Gulshan Raj